Skip to content

Commit

Permalink
fix(air purifier): improve particle filter service
Browse files Browse the repository at this point in the history
  • Loading branch information
tomekkleszcz committed Apr 3, 2024
1 parent f0a9dca commit 935e7fe
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
32 changes: 15 additions & 17 deletions src/accessories/devices/airPurifier/airPurifier.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -302,20 +301,19 @@ export class AirPurifier extends ElectroluxAccessoryController {
}

async getParticleFilterChangeIndication(): Promise<CharacteristicValue> {
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
: this.platform.Characteristic.FilterChangeIndication.FILTER_OK;
}

async getParticleFilterLifeLevel(): Promise<CharacteristicValue> {
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;
}
Expand Down Expand Up @@ -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,
Expand Down
3 changes: 2 additions & 1 deletion src/definitions/appliance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type State = 'good';
type WorkMode = 'Manual' | 'Auto' | 'PowerOff';

export enum FilterType {
ParticleFilter = 49,
ParticleFilter1 = 48,
ParticleFilter2 = 49,
OdorFilter = 192
}
5 changes: 5 additions & 0 deletions src/util/filters.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { FilterType } from '../definitions/appliance';

export const isParticleFilter = (filterType: FilterType) =>
filterType === FilterType.ParticleFilter1 ||
filterType === FilterType.ParticleFilter2;

0 comments on commit 935e7fe

Please sign in to comment.