From d95d0d7babee64c127decbcbc072093b680b1eef Mon Sep 17 00:00:00 2001 From: Nyirsh Date: Mon, 1 Jan 2024 11:04:38 -0600 Subject: [PATCH] fix: skip power state for non supported device for get & set thermostat mode ( #81) --- src/accessory/thermostat-accessory.ts | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/accessory/thermostat-accessory.ts b/src/accessory/thermostat-accessory.ts index 0a0d440..3073cf1 100644 --- a/src/accessory/thermostat-accessory.ts +++ b/src/accessory/thermostat-accessory.ts @@ -32,6 +32,7 @@ export default class ThermostatAccessory extends BaseAccessory { service: Service; namespaces = ThermostatNamespaces; isExternalAccessory = false; + isPowerSupported = true; configureServices() { this.service = @@ -132,7 +133,15 @@ export default class ThermostatAccessory extends BaseAccessory { } async handleTargetStateGet(): Promise { - const powerState = await this.handlePowerGet(); + let isDeviceOn: boolean; + try { + isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true; + } catch (e) { + this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', e); + this.isPowerSupported = false; + isDeviceOn = true; + } + const alexaNamespace: ThermostatNamespacesType = 'Alexa.ThermostatController'; const alexaValueName = 'thermostatMode'; @@ -143,7 +152,7 @@ export default class ThermostatAccessory extends BaseAccessory { namespace === alexaNamespace && name === alexaValueName, ), ), - O.map(({ value }) => powerState ? tstatMapper.mapAlexaModeToHomeKit(value, this.Characteristic): tstatMapper.mapAlexaModeToHomeKit(0, this.Characteristic), + O.map(({ value }) => isDeviceOn ? tstatMapper.mapAlexaModeToHomeKit(value, this.Characteristic): tstatMapper.mapAlexaModeToHomeKit(0, this.Characteristic), ), O.tap((s) => O.of(this.logWithContext('debug', `Get thermostat mode result: ${s}`)), @@ -166,15 +175,15 @@ export default class ThermostatAccessory extends BaseAccessory { } let isDeviceOn: boolean; - let isPowerSupported = true; try { - isDeviceOn = await this.handlePowerGet(); + isDeviceOn = this.isPowerSupported ? await this.handlePowerGet() : true; } catch (e) { this.logWithContext('debug', 'Skipping power-related logic for unsupported devices', e); + this.isPowerSupported = false; isDeviceOn = true; - isPowerSupported = false; } - if(value === 0 && isPowerSupported) { + + if(value === 0 && this.isPowerSupported) { await this.handlePowerSet(false); this.updateCacheValue({ value: tstatMapper.mapHomekitModeToAlexa(value, this.Characteristic),