From 935e7fe007c0559fcc0146031e786d4aafea706b Mon Sep 17 00:00:00 2001 From: tomekkleszcz Date: Wed, 3 Apr 2024 17:56:32 +0200 Subject: [PATCH] fix(air purifier): improve particle filter service --- .../devices/airPurifier/airPurifier.ts | 32 +++++++++---------- src/definitions/appliance.ts | 3 +- src/util/filters.ts | 5 +++ 3 files changed, 22 insertions(+), 18 deletions(-) create mode 100644 src/util/filters.ts diff --git a/src/accessories/devices/airPurifier/airPurifier.ts b/src/accessories/devices/airPurifier/airPurifier.ts index c96f90a..a2bea8c 100644 --- a/src/accessories/devices/airPurifier/airPurifier.ts +++ b/src/accessories/devices/airPurifier/airPurifier.ts @@ -1,9 +1,10 @@ import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'; import { ElectroluxDevicesPlatform } from '../../../platform'; -import { Appliance, FilterType } from '../../../definitions/appliance'; +import { Appliance } from '../../../definitions/appliance'; import { ElectroluxAccessoryController } from '../../controller'; import { Capabilities } from '../../../definitions/capabilities'; +import { isParticleFilter } from '../../../util/filters'; export class AirPurifier extends ElectroluxAccessoryController { private airPurifierService: Service; @@ -105,10 +106,8 @@ export class AirPurifier extends ElectroluxAccessoryController { ); if ( - this.appliance.properties.reported.FilterType_1 === - FilterType.ParticleFilter || - this.appliance.properties.reported.FilterType_2 === - FilterType.ParticleFilter + isParticleFilter(this.appliance.properties.reported.FilterType_1) || + isParticleFilter(this.appliance.properties.reported.FilterType_2) ) { this.particleFilterService = this.accessory.getService( @@ -302,11 +301,11 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getParticleFilterChangeIndication(): Promise { - const filterLife = - this.appliance.properties.reported.FilterType_1 === - FilterType.ParticleFilter - ? this.appliance.properties.reported.FilterLife_1 - : this.appliance.properties.reported.FilterLife_2; + const filterLife = isParticleFilter( + this.appliance.properties.reported.FilterType_1 + ) + ? this.appliance.properties.reported.FilterLife_1 + : this.appliance.properties.reported.FilterLife_2; return filterLife <= 10 ? this.platform.Characteristic.FilterChangeIndication.CHANGE_FILTER @@ -314,8 +313,7 @@ export class AirPurifier extends ElectroluxAccessoryController { } async getParticleFilterLifeLevel(): Promise { - return this.appliance.properties.reported.FilterType_1 === - FilterType.ParticleFilter + return isParticleFilter(this.appliance.properties.reported.FilterType_1) ? this.appliance.properties.reported.FilterLife_1 : this.appliance.properties.reported.FilterLife_2; } @@ -384,11 +382,11 @@ export class AirPurifier extends ElectroluxAccessoryController { this.appliance.properties.reported.Fanspeed ); - const filterLife = - this.appliance.properties.reported.FilterType_1 === - FilterType.ParticleFilter - ? this.appliance.properties.reported.FilterLife_1 - : this.appliance.properties.reported.FilterLife_2; + const filterLife = isParticleFilter( + this.appliance.properties.reported.FilterType_1 + ) + ? this.appliance.properties.reported.FilterLife_1 + : this.appliance.properties.reported.FilterLife_2; this.particleFilterService?.updateCharacteristic( this.platform.Characteristic.FilterChangeIndication, diff --git a/src/definitions/appliance.ts b/src/definitions/appliance.ts index 20116c7..41e4cd1 100644 --- a/src/definitions/appliance.ts +++ b/src/definitions/appliance.ts @@ -73,6 +73,7 @@ type State = 'good'; type WorkMode = 'Manual' | 'Auto' | 'PowerOff'; export enum FilterType { - ParticleFilter = 49, + ParticleFilter1 = 48, + ParticleFilter2 = 49, OdorFilter = 192 } diff --git a/src/util/filters.ts b/src/util/filters.ts new file mode 100644 index 0000000..0e34583 --- /dev/null +++ b/src/util/filters.ts @@ -0,0 +1,5 @@ +import { FilterType } from '../definitions/appliance'; + +export const isParticleFilter = (filterType: FilterType) => + filterType === FilterType.ParticleFilter1 || + filterType === FilterType.ParticleFilter2;