From 4cbbf6449554aafd245e8bd129b97994edd78210 Mon Sep 17 00:00:00 2001 From: Fiach Antaw Date: Fri, 2 Dec 2022 14:23:46 +1000 Subject: [PATCH] Some quality-of-life fixes for the HomeKit plugin (#448) * homekit: don't add fan services to devices without fan interfaces * homekit: set minimum step for fan based on maxSpeed * homekit: disable 'auto' mode if not supported by thermostat --- plugins/homekit/src/types/common.ts | 6 ++++++ plugins/homekit/src/types/thermostat.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/plugins/homekit/src/types/common.ts b/plugins/homekit/src/types/common.ts index 4b7d0793d..331e28b07 100644 --- a/plugins/homekit/src/types/common.ts +++ b/plugins/homekit/src/types/common.ts @@ -69,6 +69,9 @@ export function addCarbonDioxideSensor(device: ScryptedDevice & CO2Sensor, acces } export function addFan(device: ScryptedDevice & Fan & OnOff, accessory: Accessory): Service { + if (!device.interfaces.includes(ScryptedInterface.OnOff) && !device.interfaces.includes(ScryptedInterface.Fan)) + return undefined; + const service = accessory.addService(Service.Fanv2, device.name); if (device.interfaces.includes(ScryptedInterface.OnOff)) { @@ -128,6 +131,9 @@ export function addFan(device: ScryptedDevice & Fan & OnOff, accessory: Accessor speed, }); }); + service.getCharacteristic(Characteristic.RotationSpeed).setProps({ + minStep: 100 / device.fan?.maxSpeed, + }); } if (device.fan?.availableModes !== undefined) { diff --git a/plugins/homekit/src/types/thermostat.ts b/plugins/homekit/src/types/thermostat.ts index 01d2d5242..bb6182ad2 100644 --- a/plugins/homekit/src/types/thermostat.ts +++ b/plugins/homekit/src/types/thermostat.ts @@ -96,6 +96,12 @@ addSupportedType({ bindCharacteristic(device, ScryptedInterface.TemperatureSetting, service, Characteristic.TargetHeatingCoolingState, () => toTargetMode(device.thermostatMode)); + + if (!device.thermostatAvailableModes.includes(ThermostatMode.Auto)) { + service.getCharacteristic(Characteristic.TargetHeatingCoolingState).setProps({ + maxValue: Characteristic.TargetHeatingCoolingState.COOL // Disable 'Auto' mode + }); + } service.getCharacteristic(Characteristic.TargetTemperature) .on(CharacteristicEventTypes.SET, (value: CharacteristicValue, callback: CharacteristicSetCallback) => {