Add LowBattery and Active states to wireless sensors
This commit is contained in:
@@ -11,7 +11,9 @@ export class environmentSensorAccessory extends accessory {
|
||||
|
||||
private state = {
|
||||
Temperature: 0,
|
||||
Humidity: 0
|
||||
Humidity: 0,
|
||||
LowBattery: false,
|
||||
Active: false
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -63,6 +65,16 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity)
|
||||
.onGet(this.getHumidity.bind(this))
|
||||
|
||||
this.serviceTemperature.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
|
||||
this.serviceTemperature.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
this.serviceHumidity.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -81,6 +93,24 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.state.Humidity = value / 100
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
|
||||
}
|
||||
else if (key == "battery" && value != "") {
|
||||
if (value < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
}
|
||||
else if (key == "online" && value != "") {
|
||||
if (value == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -99,8 +129,24 @@ export class environmentSensorAccessory extends accessory {
|
||||
this.state.Temperature = device.temperature
|
||||
this.state.Humidity = device.humidity
|
||||
|
||||
if (device.battery < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
|
||||
if (device.online == "false") {
|
||||
this.state.Active = false
|
||||
} else {
|
||||
this.state.Active = true
|
||||
}
|
||||
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.CurrentTemperature, this.state.Temperature)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, this.state.Humidity)
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceTemperature.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
this.serviceHumidity.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
|
||||
break
|
||||
}
|
||||
@@ -119,4 +165,12 @@ export class environmentSensorAccessory extends accessory {
|
||||
getHumidity(): CharacteristicValue {
|
||||
return this.state.Humidity
|
||||
}
|
||||
|
||||
getLowBattery(): CharacteristicValue {
|
||||
return this.state.LowBattery
|
||||
}
|
||||
|
||||
getActive(): CharacteristicValue {
|
||||
return this.state.Active
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user