From 80c28b961ad064fd5dca2cf950d23b99979ec3f8 Mon Sep 17 00:00:00 2001 From: Benjamin Schwartz Date: Fri, 1 Jul 2022 02:09:34 +0000 Subject: [PATCH] add support for reading the battery for the external sensor --- src/ductless.ts | 21 +++++++++++++++++++-- src/ductless_simple.ts | 14 +++++++++++++- 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/ductless.ts b/src/ductless.ts index 573140a..798eee7 100644 --- a/src/ductless.ts +++ b/src/ductless.ts @@ -21,6 +21,8 @@ export class KumoPlatformAccessory_ductless { private PowerSwitch: Service; private Dehumidifier: Service; private Humidity: Service | null; + private HumidityBattery: Service | null; + private lastupdate; private lastquery; @@ -93,10 +95,18 @@ export class KumoPlatformAccessory_ductless { this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + this.HumidityBattery = useExternalSensor ? this.accessory.getService( + this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery) : null; + if (this.Humidity) { this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } + if (this.HumidityBattery) { + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor Battery'); + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -354,7 +364,7 @@ export class KumoPlatformAccessory_ductless { } private updateCurrentRelativeHumidity() { - if (!this.Humidity) { + if (!this.Humidity || !this.HumidityBattery) { return; } let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; @@ -364,10 +374,17 @@ export class KumoPlatformAccessory_ductless { this.platform.log.debug('setting humidity to %s', currentValue); if (ourSensor.battery) { - this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, ourSensor.battery < 10); if (ourSensor.battery < 10) { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) + + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + } else { + this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } + + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.BatteryLevel, ourSensor.battery); } } this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue); diff --git a/src/ductless_simple.ts b/src/ductless_simple.ts index 257a09b..0c5bd42 100755 --- a/src/ductless_simple.ts +++ b/src/ductless_simple.ts @@ -17,6 +17,7 @@ import { KUMO_LAG, KUMO_DEVICE_WAIT } from './settings'; export class KumoPlatformAccessory_ductless_simple { private HeaterCooler: Service; private Humidity: Service | null; + private HumidityBattery: Service | null; private lastupdate; private lastquery; @@ -61,6 +62,9 @@ export class KumoPlatformAccessory_ductless_simple { this.Humidity = useExternalSensor ? this.accessory.getService( this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor) : null; + this.HumidityBattery = useExternalSensor ? this.accessory.getService( + this.platform.Service.Battery) || this.accessory.addService(this.platform.Service.Battery) : null; + // set sevice names. this.HeaterCooler.setCharacteristic(this.platform.Characteristic.Name, 'Heater/Cooler'); @@ -68,6 +72,11 @@ export class KumoPlatformAccessory_ductless_simple { this.Humidity.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor'); } + if (this.HumidityBattery) { + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.Name, 'Humidity Sensor Battery'); + this.HumidityBattery.setCharacteristic(this.platform.Characteristic.ChargingState, this.platform.Characteristic.ChargingState.NOT_CHARGEABLE); + } + // create handlers for characteristics this.HeaterCooler.getCharacteristic(this.platform.Characteristic.Active) .on('get', this.handleActiveGet.bind(this)) @@ -359,7 +368,7 @@ export class KumoPlatformAccessory_ductless_simple { } private updateCurrentRelativeHumidity() { - if (!this.Humidity) { + if (!this.Humidity || !this.HumidityBattery) { return; } let currentValue: number = this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value; @@ -373,10 +382,13 @@ export class KumoPlatformAccessory_ductless_simple { this.platform.log.warn('!!!The sensor attached to device %s has a low battery!!!', this.accessory.context.serial) this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_LOW); } else { this.Humidity.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.StatusLowBattery, this.platform.Characteristic.StatusLowBattery.BATTERY_LEVEL_NORMAL); } + this.HumidityBattery.updateCharacteristic(this.platform.Characteristic.BatteryLevel, ourSensor.battery); } } this.Humidity.updateCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity, currentValue);