Skip to content

Commit

Permalink
add support for reading the battery for the external sensor
Browse files Browse the repository at this point in the history
  • Loading branch information
LtHummus committed Jul 1, 2022
1 parent b818282 commit 80c28b9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
21 changes: 19 additions & 2 deletions src/ductless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -354,7 +364,7 @@ export class KumoPlatformAccessory_ductless {
}

private updateCurrentRelativeHumidity() {
if (!this.Humidity) {
if (!this.Humidity || !this.HumidityBattery) {
return;
}
let currentValue: number = <number>this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value;
Expand All @@ -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);
Expand Down
14 changes: 13 additions & 1 deletion src/ductless_simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,13 +62,21 @@ 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');

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))
Expand Down Expand Up @@ -359,7 +368,7 @@ export class KumoPlatformAccessory_ductless_simple {
}

private updateCurrentRelativeHumidity() {
if (!this.Humidity) {
if (!this.Humidity || !this.HumidityBattery) {
return;
}
let currentValue: number = <number>this.Humidity.getCharacteristic(this.platform.Characteristic.CurrentRelativeHumidity).value;
Expand All @@ -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);
Expand Down

0 comments on commit 80c28b9

Please sign in to comment.