Add LowBattery and Active states to wireless sensors
This commit is contained in:
@@ -9,7 +9,9 @@ export class motionSensorAccessory extends accessory {
|
||||
private service: Service
|
||||
|
||||
private state = {
|
||||
Motion: false
|
||||
Motion: false,
|
||||
LowBattery: false,
|
||||
Active: false
|
||||
}
|
||||
|
||||
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
|
||||
@@ -58,6 +60,12 @@ export class motionSensorAccessory extends accessory {
|
||||
this.service.getCharacteristic(this.platform.Characteristic.MotionDetected)
|
||||
.onGet(this.getState.bind(this));
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusLowBattery)
|
||||
.onGet(this.getLowBattery.bind(this))
|
||||
|
||||
this.service.getCharacteristic(this.platform.Characteristic.StatusActive)
|
||||
.onGet(this.getActive.bind(this))
|
||||
|
||||
this.setName(accessory.context.device.deviceName)
|
||||
this.update()
|
||||
}
|
||||
@@ -75,6 +83,22 @@ export class motionSensorAccessory extends accessory {
|
||||
}
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
|
||||
}
|
||||
else if (key == "battery" && value != "") {
|
||||
if (value < 25) {
|
||||
this.state.LowBattery = true
|
||||
} else {
|
||||
this.state.LowBattery = false
|
||||
}
|
||||
this.service.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.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
}
|
||||
}
|
||||
|
||||
update() {
|
||||
@@ -96,7 +120,21 @@ export class motionSensorAccessory extends accessory {
|
||||
this.state.Motion = true
|
||||
}
|
||||
|
||||
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.service.updateCharacteristic(this.platform.Characteristic.MotionDetected, this.state.Motion)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
|
||||
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
|
||||
|
||||
break
|
||||
}
|
||||
@@ -111,4 +149,12 @@ export class motionSensorAccessory extends accessory {
|
||||
getState(): CharacteristicValue {
|
||||
return this.state.Motion
|
||||
}
|
||||
|
||||
getLowBattery(): CharacteristicValue {
|
||||
return this.state.LowBattery
|
||||
}
|
||||
|
||||
getActive(): CharacteristicValue {
|
||||
return this.state.Active
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user