From 69da35594ce4a33031403a0c179f1ca4cb88f5c9 Mon Sep 17 00:00:00 2001 From: Tomek Kleszcz Date: Sun, 10 Mar 2024 14:22:07 +0100 Subject: [PATCH] fix: homebridge crash when trying to update disconnected appliance state (#46) --- src/accessories/controller.ts | 28 +++ .../devices/airPurifier/airPurifier.ts | 208 +++++++----------- src/accessories/devices/airPurifier/pureA9.ts | 24 +- src/accessories/devices/airPurifier/wellA7.ts | 24 +- src/accessories/devices/comfort600.ts | 188 ++++++---------- 5 files changed, 192 insertions(+), 280 deletions(-) diff --git a/src/accessories/controller.ts b/src/accessories/controller.ts index ed67b1c..7f3fd31 100644 --- a/src/accessories/controller.ts +++ b/src/accessories/controller.ts @@ -47,5 +47,33 @@ export abstract class ElectroluxAccessoryController { } } + getCharacteristicValueGuard( + getter: () => Promise + ): () => Promise { + return async () => { + if (this.appliance.connectionState === 'Disconnected') { + throw new this.platform.api.hap.HapStatusError( + this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE + ); + } + + return await getter(); + }; + } + + setCharacteristicValueGuard( + setter: (value: CharacteristicValue) => Promise + ): (value: CharacteristicValue) => Promise { + return async (value: CharacteristicValue) => { + if (this.appliance.connectionState === 'Disconnected') { + throw new this.platform.api.hap.HapStatusError( + this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE + ); + } + + return setter(value); + }; + } + abstract update(appliance: Appliance): void; } diff --git a/src/accessories/devices/airPurifier/airPurifier.ts b/src/accessories/devices/airPurifier/airPurifier.ts index 4700e0d..91932b3 100644 --- a/src/accessories/devices/airPurifier/airPurifier.ts +++ b/src/accessories/devices/airPurifier/airPurifier.ts @@ -46,28 +46,48 @@ export class AirPurifier extends ElectroluxAccessoryController { this.airPurifierService .getCharacteristic(this.platform.Characteristic.Active) - .onGet(this.getActive.bind(this)) - .onSet(this.setActive.bind(this)); + .onGet(this.getCharacteristicValueGuard(this.getActive.bind(this))) + .onSet(this.setCharacteristicValueGuard(this.setActive.bind(this))); this.airPurifierService .getCharacteristic( this.platform.Characteristic.CurrentAirPurifierState ) - .onGet(this.getCurrentAirPurifierState.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCurrentAirPurifierState.bind(this) + ) + ); this.airPurifierService .getCharacteristic( this.platform.Characteristic.TargetAirPurifierState ) - .onGet(this.getTargetAirPurifierState.bind(this)) - .onSet(this.setTargetAirPurifierState.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getTargetAirPurifierState.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setTargetAirPurifierState.bind(this) + ) + ); this.airPurifierService .getCharacteristic( this.platform.Characteristic.LockPhysicalControls ) - .onGet(this.getLockPhysicalControls.bind(this)) - .onSet(this.setLockPhysicalControls.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getLockPhysicalControls.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setLockPhysicalControls.bind(this) + ) + ); this.airPurifierService .getCharacteristic(this.platform.Characteristic.RotationSpeed) @@ -76,8 +96,16 @@ export class AirPurifier extends ElectroluxAccessoryController { maxValue: 5, minStep: 1 }) - .onGet(this.getRotationSpeed.bind(this)) - .onSet(this.setRotationSpeed.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getRotationSpeed.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setRotationSpeed.bind(this) + ) + ); this.ionizerService = this.accessory.getService(this.platform.Service.Switch) || @@ -90,8 +118,10 @@ export class AirPurifier extends ElectroluxAccessoryController { this.ionizerService .getCharacteristic(this.platform.Characteristic.On) - .onGet(this.getIonizer.bind(this)) - .onSet(this.setIonizer.bind(this)); + .onGet(this.getCharacteristicValueGuard(this.getIonizer.bind(this))) + .onSet( + this.setCharacteristicValueGuard(this.setIonizer.bind(this)) + ); this.airQualityService = this.accessory.getService(this.platform.Service.AirQualitySensor) || @@ -99,19 +129,29 @@ export class AirPurifier extends ElectroluxAccessoryController { this.airQualityService .getCharacteristic(this.platform.Characteristic.AirQuality) - .onGet(this.getAirQuality.bind(this)); + .onGet( + this.getCharacteristicValueGuard(this.getAirQuality.bind(this)) + ); this.airQualityService .getCharacteristic(this.platform.Characteristic.PM2_5Density) - .onGet(this.getPM2_5Density.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getPM2_5Density.bind(this) + ) + ); this.airQualityService .getCharacteristic(this.platform.Characteristic.PM10Density) - .onGet(this.getPM10Density.bind(this)); + .onGet( + this.getCharacteristicValueGuard(this.getPM10Density.bind(this)) + ); this.airQualityService .getCharacteristic(this.platform.Characteristic.VOCDensity) - .onGet(this.getVOCDensity.bind(this)); + .onGet( + this.getCharacteristicValueGuard(this.getVOCDensity.bind(this)) + ); this.humiditySensorService = this.accessory.getService(this.platform.Service.HumiditySensor) || @@ -121,7 +161,11 @@ export class AirPurifier extends ElectroluxAccessoryController { .getCharacteristic( this.platform.Characteristic.CurrentRelativeHumidity ) - .onGet(this.getCurrentRelativeHumidity.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCurrentRelativeHumidity.bind(this) + ) + ); this.temperatureSensorService = this.accessory.getService( @@ -131,7 +175,11 @@ export class AirPurifier extends ElectroluxAccessoryController { this.temperatureSensorService .getCharacteristic(this.platform.Characteristic.CurrentTemperature) - .onGet(this.getCurrentTemperature.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCurrentTemperature.bind(this) + ) + ); if ( this.appliance.properties.reported.FilterType_1 === @@ -151,11 +199,19 @@ export class AirPurifier extends ElectroluxAccessoryController { .getCharacteristic( this.platform.Characteristic.FilterChangeIndication ) - .onGet(this.getParticleFilterChangeIndication.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getParticleFilterChangeIndication.bind(this) + ) + ); this.particleFilterService .getCharacteristic(this.platform.Characteristic.FilterLifeLevel) - .onGet(this.getParticleFilterLifeLevel.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getParticleFilterLifeLevel.bind(this) + ) + ); this.particleFilterService.setCharacteristic( this.platform.Characteristic.Name, @@ -169,24 +225,12 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getActive(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.Workmode === 'PowerOff' ? this.platform.Characteristic.Active.INACTIVE : this.platform.Characteristic.Active.ACTIVE; } async setActive(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - if ( (this.appliance.properties.reported.Workmode === 'PowerOff' && value === this.platform.Characteristic.Active.ACTIVE) || @@ -230,12 +274,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getCurrentAirPurifierState(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - switch (this.appliance.properties.reported.Workmode) { case 'Manual': return this.platform.Characteristic.CurrentAirPurifierState @@ -250,12 +288,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getTargetAirPurifierState(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - switch (this.appliance.properties.reported.Workmode) { case 'Manual': return this.platform.Characteristic.TargetAirPurifierState @@ -268,12 +300,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async setTargetAirPurifierState(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - let workMode; switch (value) { case this.platform.Characteristic.TargetAirPurifierState.MANUAL: @@ -292,12 +318,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getLockPhysicalControls(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.SafetyLock ? this.platform.Characteristic.LockPhysicalControls .CONTROL_LOCK_ENABLED @@ -306,12 +326,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async setLockPhysicalControls(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - await this.sendCommand({ SafetyLock: value === @@ -326,22 +340,10 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getRotationSpeed(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.Fanspeed; } async setRotationSpeed(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - if (value === 0) { await this.sendCommand({ Workmode: 'PowerOff' @@ -377,22 +379,10 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getIonizer(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.Ionizer; } async setIonizer(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - await this.sendCommand({ Ionizer: value }); @@ -401,12 +391,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getAirQuality(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - if (this.appliance.properties.reported.PM2_5 <= 25) { return this.platform.Characteristic.AirQuality.EXCELLENT; } else if (this.appliance.properties.reported.PM2_5 <= 50) { @@ -421,32 +405,14 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getPM2_5Density(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.PM2_5; } async getPM10Density(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.PM10; } async getVOCDensity(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - const vocDensity = tvocPPBToVocDensity( this.appliance.properties.reported.TVOC, this.appliance.properties.reported.Temp, @@ -457,32 +423,14 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getCurrentRelativeHumidity(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.Humidity; } async getCurrentTemperature(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.Temp; } async getParticleFilterChangeIndication(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - const filterLife = this.appliance.properties.reported.FilterType_1 === FilterType.ParticleFilter @@ -495,12 +443,6 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getParticleFilterLifeLevel(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.FilterType_1 === FilterType.ParticleFilter ? this.appliance.properties.reported.FilterLife_1 diff --git a/src/accessories/devices/airPurifier/pureA9.ts b/src/accessories/devices/airPurifier/pureA9.ts index 390d958..beaef51 100644 --- a/src/accessories/devices/airPurifier/pureA9.ts +++ b/src/accessories/devices/airPurifier/pureA9.ts @@ -26,20 +26,22 @@ export class PureA9 extends AirPurifier { .getCharacteristic( this.platform.Characteristic.CarbonDioxideDetected ) - .onGet(this.getCarbonDioxideDetected.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCarbonDioxideDetected.bind(this) + ) + ); this.carbonDioxideSensorService .getCharacteristic(this.platform.Characteristic.CarbonDioxideLevel) - .onGet(this.getCarbonDioxideLevel.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCarbonDioxideLevel.bind(this) + ) + ); } async getCarbonDioxideDetected(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.ECO2 > this.platform.config.carbonDioxideSensorAlarmValue ? this.platform.Characteristic.CarbonDioxideDetected @@ -49,12 +51,6 @@ export class PureA9 extends AirPurifier { } async getCarbonDioxideLevel(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.ECO2; } diff --git a/src/accessories/devices/airPurifier/wellA7.ts b/src/accessories/devices/airPurifier/wellA7.ts index a6a2a98..a2cb0e7 100644 --- a/src/accessories/devices/airPurifier/wellA7.ts +++ b/src/accessories/devices/airPurifier/wellA7.ts @@ -26,20 +26,22 @@ export class WellA7 extends AirPurifier { .getCharacteristic( this.platform.Characteristic.CarbonDioxideDetected ) - .onGet(this.getCarbonDioxideDetected.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCarbonDioxideDetected.bind(this) + ) + ); this.carbonDioxideSensorService .getCharacteristic(this.platform.Characteristic.CarbonDioxideLevel) - .onGet(this.getCarbonDioxideLevel.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCarbonDioxideLevel.bind(this) + ) + ); } async getCarbonDioxideDetected(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.ECO2 > this.platform.config.carbonDioxideSensorAlarmValue ? this.platform.Characteristic.CarbonDioxideDetected @@ -49,12 +51,6 @@ export class WellA7 extends AirPurifier { } async getCarbonDioxideLevel(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.ECO2; } diff --git a/src/accessories/devices/comfort600.ts b/src/accessories/devices/comfort600.ts index f21f48e..ce69584 100644 --- a/src/accessories/devices/comfort600.ts +++ b/src/accessories/devices/comfort600.ts @@ -86,60 +86,112 @@ export class Comfort600 extends ElectroluxAccessoryController { this.service .getCharacteristic(this.platform.Characteristic.Active) - .onGet(this.getActive.bind(this)) - .onSet(this.setActive.bind(this)); + .onGet(this.getCharacteristicValueGuard(this.getActive.bind(this))) + .onSet(this.setCharacteristicValueGuard(this.setActive.bind(this))); this.service .getCharacteristic( this.platform.Characteristic.CurrentHeaterCoolerState ) - .onGet(this.getCurrentHeaterCoolerState.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCurrentHeaterCoolerState.bind(this) + ) + ); this.service .getCharacteristic( this.platform.Characteristic.TargetHeaterCoolerState ) - .onGet(this.getTargetHeaterCoolerState.bind(this)) - .onSet(this.setTargetHeaterCoolerState.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getTargetHeaterCoolerState.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setTargetHeaterCoolerState.bind(this) + ) + ); this.service .getCharacteristic(this.platform.Characteristic.CurrentTemperature) - .onGet(this.getCurrentTemperature.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCurrentTemperature.bind(this) + ) + ); this.service .getCharacteristic( this.platform.Characteristic.LockPhysicalControls ) - .onGet(this.getLockPhysicalControls.bind(this)) - .onSet(this.setLockPhysicalControls.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getLockPhysicalControls.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setLockPhysicalControls.bind(this) + ) + ); this.service .getCharacteristic(this.platform.Characteristic.Name) - .onGet(this.getName.bind(this)); + .onGet(this.getCharacteristicValueGuard(this.getName.bind(this))); this.service .getCharacteristic(this.platform.Characteristic.RotationSpeed) - .onGet(this.getRotationSpeed.bind(this)) - .onSet(this.setRotationSpeed.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getRotationSpeed.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setRotationSpeed.bind(this) + ) + ); this.service .getCharacteristic(this.platform.Characteristic.SwingMode) - .onGet(this.getSwingMode.bind(this)) - .onSet(this.setSwingMode.bind(this)); + .onGet( + this.getCharacteristicValueGuard(this.getSwingMode.bind(this)) + ) + .onSet( + this.setCharacteristicValueGuard(this.setSwingMode.bind(this)) + ); this.service .getCharacteristic( this.platform.Characteristic.CoolingThresholdTemperature ) - .onGet(this.getCoolingThresholdTemperature.bind(this)) - .onSet(this.setCoolingThresholdTemperature.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getCoolingThresholdTemperature.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setCoolingThresholdTemperature.bind(this) + ) + ); this.service .getCharacteristic( this.platform.Characteristic.HeatingThresholdTemperature ) - .onGet(this.getHeatingThresholdTemperature.bind(this)) - .onSet(this.setHeatingThresholdTemperature.bind(this)); + .onGet( + this.getCharacteristicValueGuard( + this.getHeatingThresholdTemperature.bind(this) + ) + ) + .onSet( + this.setCharacteristicValueGuard( + this.setHeatingThresholdTemperature.bind(this) + ) + ); } private setTemperature = _.debounce(async (value: CharacteristicValue) => { @@ -149,24 +201,12 @@ export class Comfort600 extends ElectroluxAccessoryController { }, 1000); async getActive(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.applianceState === 'running' ? this.platform.Characteristic.Active.ACTIVE : this.platform.Characteristic.Active.INACTIVE; } async setActive(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - this.sendCommand({ executeCommand: value === this.platform.Characteristic.Active.ACTIVE @@ -181,12 +221,6 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getCurrentHeaterCoolerState(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - switch (this.appliance.properties.reported.mode) { case 'cool': return this.platform.Characteristic.CurrentHeaterCoolerState @@ -205,12 +239,6 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getTargetHeaterCoolerState(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - switch (this.appliance.properties.reported.mode) { case 'cool': return this.platform.Characteristic.TargetHeaterCoolerState @@ -225,12 +253,6 @@ export class Comfort600 extends ElectroluxAccessoryController { } async setTargetHeaterCoolerState(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - let mode: Uppercase | null = null; let currentState: CharacteristicValue | null = null; @@ -308,22 +330,10 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getCurrentTemperature(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.ambientTemperatureC; } async getLockPhysicalControls(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.uiLockMode ? this.platform.Characteristic.LockPhysicalControls .CONTROL_LOCK_ENABLED @@ -332,12 +342,6 @@ export class Comfort600 extends ElectroluxAccessoryController { } async setLockPhysicalControls(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - await this.sendCommand({ uiLockMode: value === @@ -352,22 +356,10 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getName(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.accessory.displayName; } async getRotationSpeed(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - switch (this.appliance.properties.reported.fanSpeedSetting) { case 'auto': return 0; @@ -381,12 +373,6 @@ export class Comfort600 extends ElectroluxAccessoryController { } async setRotationSpeed(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - await this.sendCommand({ fanSpeed: value }); @@ -404,24 +390,12 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getSwingMode(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.verticalSwing === 'on' ? this.platform.Characteristic.SwingMode.SWING_ENABLED : this.platform.Characteristic.SwingMode.SWING_DISABLED; } async setSwingMode(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - await this.sendCommand({ verticalSwing: value === this.platform.Characteristic.SwingMode.SWING_ENABLED @@ -436,22 +410,10 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getCoolingThresholdTemperature(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.targetTemperatureC; } async setCoolingThresholdTemperature(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - try { await this.setTemperature(value); this.appliance.properties.reported.targetTemperatureC = @@ -464,22 +426,10 @@ export class Comfort600 extends ElectroluxAccessoryController { } async getHeatingThresholdTemperature(): Promise { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - return this.appliance.properties.reported.targetTemperatureC; } async setHeatingThresholdTemperature(value: CharacteristicValue) { - if (this.appliance.connectionState === 'Disconnected') { - throw new this.platform.api.hap.HapStatusError( - this.platform.api.hap.HAPStatus.SERVICE_COMMUNICATION_FAILURE - ); - } - try { await this.setTemperature(value); this.appliance.properties.reported.targetTemperatureC =