From e68f96dd5e1a3142003a5140f0e057dc218be036 Mon Sep 17 00:00:00 2001 From: Tomek Kleszcz Date: Fri, 7 Jul 2023 12:28:26 +0200 Subject: [PATCH] feat: implement support for pure a9 --- README.md | 1 + config.schema.json | 8 ++- package.json | 2 +- .../{wellA7.ts => airPurifier/airPurifier.ts} | 56 +++++++++++-------- src/accessories/devices/airPurifier/pureA9.ts | 51 +++++++++++++++++ src/accessories/devices/airPurifier/wellA7.ts | 51 +++++++++++++++++ src/const/devices.ts | 9 ++- src/definitions/appliance.ts | 9 ++- 8 files changed, 157 insertions(+), 30 deletions(-) rename src/accessories/devices/{wellA7.ts => airPurifier/airPurifier.ts} (90%) create mode 100644 src/accessories/devices/airPurifier/pureA9.ts create mode 100644 src/accessories/devices/airPurifier/wellA7.ts diff --git a/README.md b/README.md index ac9dca5..ebbe4a3 100644 --- a/README.md +++ b/README.md @@ -21,5 +21,6 @@ This is a plugin for connecting Electrolux devices which are controlled by the [ ## 🌡️ Supported devices - Comfort 600 air conditioner - Well A7 air purifier +- Pure A9/AX 9 air purifier If your device is not on the list, please create the issue. I'll be more than happy to implement the support for your device. 😄 \ No newline at end of file diff --git a/config.schema.json b/config.schema.json index 70dfced..a582afb 100644 --- a/config.schema.json +++ b/config.schema.json @@ -21,7 +21,13 @@ "title": "Polling interval", "type": "number", "required": false, - "default": "10" + "default": "30" + }, + "carbonDioxideSensorAlarmValue": { + "title": "Carbon dioxide sensor alarm value", + "type": "number", + "required": false, + "default": "1000" } } } diff --git a/package.json b/package.json index 1f82bee..9df144c 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "displayName": "Homebridge Electrolux Devices", "name": "homebridge-electrolux-devices", - "version": "0.0.2", + "version": "0.0.3", "description": "Homebridge plugin for Electrolux devices", "license": "Apache-2.0", "repository": { diff --git a/src/accessories/devices/wellA7.ts b/src/accessories/devices/airPurifier/airPurifier.ts similarity index 90% rename from src/accessories/devices/wellA7.ts rename to src/accessories/devices/airPurifier/airPurifier.ts index 59967e9..364b482 100644 --- a/src/accessories/devices/wellA7.ts +++ b/src/accessories/devices/airPurifier/airPurifier.ts @@ -1,14 +1,13 @@ import {CharacteristicValue, PlatformAccessory, Service} from 'homebridge'; -import { ElectroluxDevicesPlatform } from '../../platform'; -import { Appliance } from '../../definitions/appliance'; -import { ElectroluxAccessoryController } from '../controller'; +import { ElectroluxDevicesPlatform } from '../../../platform'; +import { Appliance } from '../../../definitions/appliance'; +import { ElectroluxAccessoryController } from '../../controller'; -export class WellA7 extends ElectroluxAccessoryController { +export class AirPurifier extends ElectroluxAccessoryController { private airPurifierService: Service; private airQualityService: Service; - private carbonDioxideSensorService: Service; private humiditySensorService: Service; private temperatureSensorService: Service; @@ -65,15 +64,6 @@ export class WellA7 extends ElectroluxAccessoryController { this.airQualityService.getCharacteristic(this.platform.Characteristic.VOCDensity) .onGet(this.getVOCDensity.bind(this)); - this.carbonDioxideSensorService = this.accessory.getService(this.platform.Service.CarbonDioxideSensor) || - this.accessory.addService(this.platform.Service.CarbonDioxideSensor); - - this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideDetected) - .onGet(this.getCarbonDioxideDetected.bind(this)); - - this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideLevel) - .onGet(this.getCarbonDioxideLevel.bind(this)); - this.humiditySensorService = this.accessory.getService(this.platform.Service.HumiditySensor) || this.accessory.addService(this.platform.Service.HumiditySensor); @@ -243,15 +233,6 @@ export class WellA7 extends ElectroluxAccessoryController { return this.appliance.properties.reported.TVOC; } - async getCarbonDioxideDetected(): Promise { - return this.appliance.properties.reported.ECO2 > 1000 ? - this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL : - this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL; - } - - async getCarbonDioxideLevel(): Promise { - return this.appliance.properties.reported.ECO2; - } async getCurrentRelativeHumidity(): Promise { return this.appliance.properties.reported.Humidity; @@ -261,7 +242,7 @@ export class WellA7 extends ElectroluxAccessoryController { return this.appliance.properties.reported.Temp; } - update(appliance: Appliance) { + async update(appliance: Appliance) { this.appliance = appliance; switch(this.appliance.properties.reported.Workmode) { @@ -319,6 +300,33 @@ export class WellA7 extends ElectroluxAccessoryController { this.platform.Characteristic.RotationSpeed, this.appliance.properties.reported.Fanspeed * 20 ); + + this.airQualityService.updateCharacteristic( + this.platform.Characteristic.AirQuality, + await this.getAirQuality() + ); + this.airQualityService.updateCharacteristic( + this.platform.Characteristic.PM2_5Density, + this.appliance.properties.reported.PM2_5 + ); + this.airQualityService.updateCharacteristic( + this.platform.Characteristic.PM10Density, + this.appliance.properties.reported.PM10 + ); + this.airQualityService.updateCharacteristic( + this.platform.Characteristic.VOCDensity, + this.appliance.properties.reported.TVOC + ); + + this.humiditySensorService.updateCharacteristic( + this.platform.Characteristic.CurrentRelativeHumidity, + this.appliance.properties.reported.Humidity + ); + + this.temperatureSensorService.updateCharacteristic( + this.platform.Characteristic.CurrentTemperature, + this.appliance.properties.reported.Temp + ); } } \ No newline at end of file diff --git a/src/accessories/devices/airPurifier/pureA9.ts b/src/accessories/devices/airPurifier/pureA9.ts new file mode 100644 index 0000000..8f88fc9 --- /dev/null +++ b/src/accessories/devices/airPurifier/pureA9.ts @@ -0,0 +1,51 @@ +import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'; +import { AirPurifier } from './airPurifier'; +import { ElectroluxDevicesPlatform } from '../../../platform'; +import { ElectroluxAccessoryController } from '../../controller'; +import { Appliance } from '../../../definitions/appliance'; + +export class PureA9 extends AirPurifier { + + private carbonDioxideSensorService: Service; + + constructor( + readonly _platform: ElectroluxDevicesPlatform, + readonly _accessory: PlatformAccessory, + readonly _appliance: Appliance + ) { + super(_platform, _accessory, _appliance); + + this.carbonDioxideSensorService = this.accessory.getService(this.platform.Service.CarbonDioxideSensor) || + this.accessory.addService(this.platform.Service.CarbonDioxideSensor); + + this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideDetected) + .onGet(this.getCarbonDioxideDetected.bind(this)); + + this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideLevel) + .onGet(this.getCarbonDioxideLevel.bind(this)); + } + + async getCarbonDioxideDetected(): Promise { + return this.appliance.properties.reported.ECO2 > 1000 ? + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL : + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL; + } + + async getCarbonDioxideLevel(): Promise { + return this.appliance.properties.reported.ECO2; + } + + async update(appliance: Appliance) { + this.appliance = appliance; + + this.carbonDioxideSensorService.updateCharacteristic( + this.platform.Characteristic.CarbonDioxideDetected, this.appliance.properties.reported.CO2 > this.platform.config.carbonDioxideSensorAlarmValue ? + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL : + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL + ); + this.carbonDioxideSensorService.updateCharacteristic( + this.platform.Characteristic.CarbonDioxideLevel, this.appliance.properties.reported.CO2 + ); + } + +} \ No newline at end of file diff --git a/src/accessories/devices/airPurifier/wellA7.ts b/src/accessories/devices/airPurifier/wellA7.ts new file mode 100644 index 0000000..56d4c02 --- /dev/null +++ b/src/accessories/devices/airPurifier/wellA7.ts @@ -0,0 +1,51 @@ +import { CharacteristicValue, PlatformAccessory, Service } from 'homebridge'; +import { ElectroluxDevicesPlatform } from '../../../platform'; +import { AirPurifier } from './airPurifier'; +import { ElectroluxAccessoryController } from '../../controller'; +import { Appliance } from '../../../definitions/appliance'; + +export class WellA7 extends AirPurifier { + + private carbonDioxideSensorService: Service; + + constructor( + readonly _platform: ElectroluxDevicesPlatform, + readonly _accessory: PlatformAccessory, + readonly _appliance: Appliance + ) { + super(_platform, _accessory, _appliance); + + this.carbonDioxideSensorService = this.accessory.getService(this.platform.Service.CarbonDioxideSensor) || + this.accessory.addService(this.platform.Service.CarbonDioxideSensor); + + this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideDetected) + .onGet(this.getCarbonDioxideDetected.bind(this)); + + this.carbonDioxideSensorService.getCharacteristic(this.platform.Characteristic.CarbonDioxideLevel) + .onGet(this.getCarbonDioxideLevel.bind(this)); + } + + async getCarbonDioxideDetected(): Promise { + return this.appliance.properties.reported.ECO2 > 1000 ? + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL : + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL; + } + + async getCarbonDioxideLevel(): Promise { + return this.appliance.properties.reported.ECO2; + } + + async update(appliance: Appliance) { + this.appliance = appliance; + + this.carbonDioxideSensorService.updateCharacteristic( + this.platform.Characteristic.CarbonDioxideDetected, this.appliance.properties.reported.ECO2 > this.platform.config.carbonDioxideSensorAlarmValue ? + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_ABNORMAL : + this.platform.Characteristic.CarbonDioxideDetected.CO2_LEVELS_NORMAL + ); + this.carbonDioxideSensorService.updateCharacteristic( + this.platform.Characteristic.CarbonDioxideLevel, this.appliance.properties.reported.ECO2 + ); + } + +} \ No newline at end of file diff --git a/src/const/devices.ts b/src/const/devices.ts index 1228925..836ac0d 100644 --- a/src/const/devices.ts +++ b/src/const/devices.ts @@ -1,7 +1,12 @@ import { Comfort600 } from '../accessories/devices/comfort600'; -import { WellA7 } from '../accessories/devices/wellA7'; +import { WellA7 } from '../accessories/devices/airPurifier/wellA7'; +import { PureA9 } from '../accessories/devices/airPurifier/pureA9'; export const DEVICES = { + /* Air conditioners */ 'Azul': Comfort600, - 'WELLA7': WellA7 + + /* Air purifiers */ + 'WELLA7': WellA7, + 'PUREA9': PureA9 }; \ No newline at end of file diff --git a/src/definitions/appliance.ts b/src/definitions/appliance.ts index 1b7bea7..656bf00 100644 --- a/src/definitions/appliance.ts +++ b/src/definitions/appliance.ts @@ -23,7 +23,7 @@ type ApplianceProperties = { filterState: State; ambientTemperatureC: number; - /* Well A7 */ + /* Air purifiers */ Workmode: WorkMode; Fanspeed: number; Ionizer: boolean; @@ -34,8 +34,13 @@ type ApplianceProperties = { PM10: number; Temp: number; Humidity: number; - ECO2: number; TVOC: number; + + /* Well A7 */ + ECO2: number; + + /* Pure A9 */ + CO2: number; }; /* Comfort 600 */