Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add air clean functionality #248

Merged
merged 2 commits into from
Aug 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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