From 9a52c99eb83fd873b35049f3b645b92cf75cea1f Mon Sep 17 00:00:00 2001 From: Billy Zoellers Date: Tue, 16 Nov 2021 15:09:52 -0500 Subject: [PATCH] thermostat: support thermostat range --- plugins/homekit/src/types/thermostat.ts | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/plugins/homekit/src/types/thermostat.ts b/plugins/homekit/src/types/thermostat.ts index 597e0a6cf..b70192d54 100644 --- a/plugins/homekit/src/types/thermostat.ts +++ b/plugins/homekit/src/types/thermostat.ts @@ -67,12 +67,6 @@ addSupportedType({ bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.TargetHeatingCoolingState, () => toTargetMode(device.thermostatMode)); - function getTargetTemperature() { - return device.thermostatSetpoint || - ((device.thermostatSetpointHigh + device.thermostatSetpointLow) / 2) || - device.temperature; - } - service.getCharacteristic(Characteristic.TargetTemperature) .on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => { callback(); @@ -80,8 +74,25 @@ addSupportedType({ }); bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.TargetTemperature, - () => getTargetTemperature()); + () => device.thermostatSetpoint || 0); + service.getCharacteristic(Characteristic.HeatingThresholdTemperature) + .on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => { + callback(); + device.setThermostatSetpointLow(value as number); + }); + + bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.HeatingThresholdTemperature, + () => device.thermostatSetpointLow || 0); + + service.getCharacteristic(Characteristic.CoolingThresholdTemperature) + .on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => { + callback(); + device.setThermostatSetpointHigh(value as number); + }); + + bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.CoolingThresholdTemperature, + () => device.thermostatSetpointHigh || 0); bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.TemperatureDisplayUnits, () => device.temperatureUnit === TemperatureUnit.C ? Characteristic.TemperatureDisplayUnits.CELSIUS : Characteristic.TemperatureDisplayUnits.FAHRENHEIT);