Add LowBattery and Active states to wireless sensors

This commit is contained in:
2025-03-03 14:33:49 +01:00
parent e9459044a0
commit 2620420ed5
3 changed files with 148 additions and 2 deletions
+46
View File
@@ -10,6 +10,8 @@ export class doorWindowSensorAccessory extends accessory {
private state = {
ContactSensorState: this.platform.Characteristic.ContactSensorState.CONTACT_DETECTED,
LowBattery: false,
Active: false
}
static async discoverDevices(platform: domoticaPlatform): Promise<device[]> {
@@ -62,6 +64,12 @@ export class doorWindowSensorAccessory extends accessory {
this.service.getCharacteristic(this.platform.Characteristic.ContactSensorState)
.onGet(this.getContactSensorState.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()
}
@@ -79,6 +87,22 @@ export class doorWindowSensorAccessory extends accessory {
}
this.service.updateCharacteristic(this.platform.Characteristic.ContactSensorState, this.state.ContactSensorState)
}
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() {
@@ -100,7 +124,21 @@ export class doorWindowSensorAccessory extends accessory {
this.state.ContactSensorState = this.platform.Characteristic.ContactSensorState.CONTACT_NOT_DETECTED
}
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.ContactSensorState, this.state.ContactSensorState)
this.service.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.state.LowBattery)
this.service.updateCharacteristic(this.platform.Characteristic.StatusActive, this.state.Active)
break
}
@@ -115,4 +153,12 @@ export class doorWindowSensorAccessory extends accessory {
getContactSensorState(): CharacteristicValue {
return this.state.ContactSensorState
}
getLowBattery(): CharacteristicValue {
return this.state.LowBattery
}
getActive(): CharacteristicValue {
return this.state.Active
}
}