Skip to content

Commit

Permalink
Add air clean functionality (#248)
Browse files Browse the repository at this point in the history
* Add air clean switch

* Fix air clean state won't update
  • Loading branch information
furkanilgenci authored Aug 7, 2023
1 parent ca91aad commit 895a190
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/devices/AirConditioner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ export default class AirConditioner extends baseDevice {
protected serviceJetMode; // jet mode
protected serviceQuietMode;
protected serviceEnergySaveMode;
protected serviceAirClean;
protected jetModeModels = ['RAC_056905'];
protected quietModeModels = ['WINF_056905'];
protected energySaveModeModels = ['WINF_056905'];
protected airCleanModels = ['RAC_056905'];
protected currentTargetState = 2; // default target: COOL

protected serviceLabelButtons;
Expand Down Expand Up @@ -127,6 +129,13 @@ export default class AirConditioner extends baseDevice {
.onSet(this.setEnergySaveActive.bind(this));
}

if (this.airCleanModels.includes(device.model)) {
this.serviceAirClean = accessory.getService('Air Purify') || accessory.addService(Switch, 'Air Purify', 'Air Purify');
this.serviceAirClean.updateCharacteristic(platform.Characteristic.Name, 'Air Purify');
this.serviceAirClean.getCharacteristic(platform.Characteristic.On)
.onSet(this.setAirCleanActive.bind(this));
}

this.setupButton(device);
}

Expand Down Expand Up @@ -162,6 +171,20 @@ export default class AirConditioner extends baseDevice {
}
}

async setAirCleanActive(value: CharacteristicValue) {
const device: Device = this.accessory.context.device;

if (this.Status.isPowerOn && this.Status.opMode === 0) {
this.platform.ThinQ?.deviceControl(device.id, {
dataKey: 'airState.wMode.airClean',
dataValue: value ? 1 : 0,
}).then(() => {
device.data.snapshot['airState.wMode.airClean'] = value ? 1 : 0;
this.updateAccessoryCharacteristic(device);
});
}
}

async setQuietModeActive(value: CharacteristicValue) {
const device: Device = this.accessory.context.device;

Expand Down Expand Up @@ -303,6 +326,10 @@ export default class AirConditioner extends baseDevice {
if (this.energySaveModeModels.includes(device.model)) {
this.serviceEnergySaveMode.updateCharacteristic(Characteristic.On, !!device.snapshot['airState.powerSave.basic']);
}

if (this.airCleanModels.includes(device.model)) {
this.serviceAirClean.updateCharacteristic(Characteristic.On, !!device.snapshot['airState.wMode.airClean']);
}
}

async setLight(value: CharacteristicValue) {
Expand Down

0 comments on commit 895a190

Please sign in to comment.