Skip to content

Commit

Permalink
add: new washer type 223
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin committed Feb 13, 2024
1 parent 4dc866a commit 8229b94
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 34 deletions.
7 changes: 6 additions & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@
"title": "Enable program finished trigger?",
"type": "boolean"
},
"washer_tub_clean": {
"title": "Enable Tub Clean Event",
"type": "boolean"
},
"washer_trigger": {
"title": "Enable program finished trigger?",
"type": "boolean"
Expand Down Expand Up @@ -304,10 +308,11 @@
"expanded": false,
"items": [
"devices[].washer_trigger",
"devices[].washer_tub_clean",
"devices[].washer_door_lock"
],
"condition": {
"functionBody": "return model.devices && model.devices[arrayIndices] && ['WASHER','WASHER_NEW', 'WASH_TOWER', 'DRYER'].includes(model.devices[arrayIndices].type);"
"functionBody": "return model.devices && model.devices[arrayIndices] && ['WASHER','WASHER_NEW', 'WASH_TOWER', 'DRYER', 'WASH_TOWER_2'].includes(model.devices[arrayIndices].type);"
}
},
{
Expand Down
58 changes: 26 additions & 32 deletions src/devices/WasherDryer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export default class WasherDryer extends baseDevice {
OccupancySensor,
LockMechanism,
Valve,
StatelessProgrammableSwitch,
},
Characteristic,
Characteristic: {
Expand All @@ -47,12 +46,6 @@ export default class WasherDryer extends baseDevice {

this.serviceWasherDryer.getCharacteristic(Characteristic.Active)
.onSet(this.setActive.bind(this))
.setProps({
perms: [
Perms.PAIRED_READ,
Perms.NOTIFY,
],
})
.updateValue(Characteristic.Active.INACTIVE);
this.serviceWasherDryer.setCharacteristic(Characteristic.Name, device.name);
this.serviceWasherDryer.setCharacteristic(Characteristic.ValveType, Characteristic.ValveType.WATER_FAUCET);
Expand Down Expand Up @@ -85,14 +78,15 @@ export default class WasherDryer extends baseDevice {
accessory.removeService(this.serviceDoorLock);
}

this.serviceEventFinished = accessory.getService(OccupancySensor);
this.serviceEventFinished = accessory.getService('Program Finished');
if (this.config.washer_trigger as boolean) {
if (!this.serviceEventFinished) {
this.serviceEventFinished = accessory.addService(OccupancySensor, 'Program Finished', 'Program Finished');
this.serviceEventFinished.addOptionalCharacteristic(Characteristic.ConfiguredName);
this.serviceEventFinished.updateCharacteristic(Characteristic.ConfiguredName, 'Program Finished');
}

this.serviceEventFinished.setCharacteristic(Characteristic.Name, 'Program Finished');
// eslint-disable-next-line max-len
this.serviceEventFinished.updateCharacteristic(Characteristic.OccupancyDetected, Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED);
} else if (this.serviceEventFinished) {
Expand All @@ -101,18 +95,25 @@ export default class WasherDryer extends baseDevice {

// tub clean coach
this.serviceTubCleanMaintenance = accessory.getService('Tub Clean Coach');
if (!this.serviceTubCleanMaintenance) {
this.serviceTubCleanMaintenance = accessory.addService(StatelessProgrammableSwitch, 'Tub Clean Coach', 'Tub Clean Coach');
this.serviceTubCleanMaintenance.addOptionalCharacteristic(Characteristic.ConfiguredName);
this.serviceTubCleanMaintenance.updateCharacteristic(Characteristic.ConfiguredName, 'Tub Clean Coach');
}
if (this.config.washer_tub_clean as boolean) {
if (!this.serviceTubCleanMaintenance) {
this.serviceTubCleanMaintenance = accessory.addService(OccupancySensor, 'Tub Clean Coach', 'Tub Clean Coach');
this.serviceTubCleanMaintenance.addOptionalCharacteristic(Characteristic.ConfiguredName);
this.serviceTubCleanMaintenance.updateCharacteristic(Characteristic.ConfiguredName, 'Tub Clean Coach');
}

this.serviceTubCleanMaintenance.updateCharacteristic(Characteristic.Name, 'Tub Clean Coach');
this.serviceTubCleanMaintenance.getCharacteristic(Characteristic.ProgrammableSwitchEvent)
.setProps({
validValues: [0], // single press
});
this.serviceWasherDryer.addLinkedService(this.serviceTubCleanMaintenance);
this.serviceTubCleanMaintenance.setCharacteristic(Characteristic.Name, 'Tub Clean Coach');
// eslint-disable-next-line max-len
this.serviceTubCleanMaintenance.updateCharacteristic(Characteristic.OccupancyDetected, Characteristic.OccupancyDetected.OCCUPANCY_NOT_DETECTED);

this.serviceTubCleanMaintenance.setCharacteristic(Characteristic.Name, 'Tub Clean Coach');
this.serviceTubCleanMaintenance.getCharacteristic(Characteristic.ProgrammableSwitchEvent)
.setProps({
validValues: [0], // single press
});
} else if (this.serviceTubCleanMaintenance) {
accessory.removeService(this.serviceTubCleanMaintenance);
}
}

public get Status() {
Expand All @@ -123,15 +124,13 @@ export default class WasherDryer extends baseDevice {
return Object.assign({}, {
washer_trigger: false,
washer_door_lock: false,
washer_tub_clean: false,
}, super.config);
}

async setActive(value: CharacteristicValue) {
if (!this.Status.isRemoteStartEnable) {
return;
}

return;
// do nothing, revert back
this.updateAccessoryCharacteristic(this.accessory.context.device);
}

public updateAccessoryCharacteristic(device: Device) {
Expand Down Expand Up @@ -168,7 +167,6 @@ export default class WasherDryer extends baseDevice {
const {
Characteristic: {
OccupancyDetected,
ProgrammableSwitchEvent,
},
} = this.platform;

Expand Down Expand Up @@ -196,17 +194,13 @@ export default class WasherDryer extends baseDevice {
}
}

if ('TCLCount' in washerDryer) {
if ('TCLCount' in washerDryer && this.serviceTubCleanMaintenance) {
// detect if tub clean coach counter is reached
if (this.Status.TCLCount >= 30) {
// trigger tub clean coach if not triggered yet
if (!this.isServiceTubCleanMaintenanceTriggered) {
this.serviceTubCleanMaintenance.updateCharacteristic(ProgrammableSwitchEvent, ProgrammableSwitchEvent.SINGLE_PRESS);
this.isServiceTubCleanMaintenanceTriggered = true;
}
this.serviceTubCleanMaintenance.updateCharacteristic(OccupancyDetected, OccupancyDetected.OCCUPANCY_DETECTED);
} else {
// reset tub clean coach trigger flag
this.isServiceTubCleanMaintenanceTriggered = false;
this.serviceTubCleanMaintenance.updateCharacteristic(OccupancyDetected, OccupancyDetected.OCCUPANCY_NOT_DETECTED);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions src/devices/WasherDryer2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import WasherDryer, {WasherDryerStatus} from './WasherDryer';

export default class WasherDryer2 extends WasherDryer {
public get Status() {
return new WasherDryerStatus(this.accessory.context.device.snapshot?.washer, this.accessory.context.device.deviceModel);
}

public update(snapshot) {
// override washer to washerDryer
snapshot.washerDryer = snapshot.washer;

super.update(snapshot);
}
}
4 changes: 3 additions & 1 deletion src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Styler from './devices/Styler';
import RangeHood from './devices/RangeHood';
import Oven from './devices/Oven';
import Microwave from './devices/Microwave';
import WasherDryer2 from './devices/WasherDryer2';

/**
* Platform Accessory
Expand All @@ -34,8 +35,9 @@ export class Helper {
case 'WASHER':
case 'WASHER_NEW':
case 'WASH_TOWER':
case 'DRYER':
return WasherDryer;
case 'DRYER': return WasherDryer;
case 'WASH_TOWER_2': return WasherDryer2; // new kind of washer
case 'DISHWASHER': return Dishwasher;
case 'DEHUMIDIFIER': return Dehumidifier;
case 'AC': return AirConditioner;
Expand Down
5 changes: 5 additions & 0 deletions src/lib/ThinQ.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ export class ThinQ {
await this.persist.setItem(device.id, deviceModel);
}

const modelVersion = parseFloat(deviceModel.Info?.version);
if (modelVersion && modelVersion >= 3 && deviceModel.Info?.defaultTargetDeviceRoot) {
deviceModel = deviceModel[deviceModel.Info.defaultTargetDeviceRoot];
}

return this.deviceModel[device.id] = device.deviceModel = new DeviceModel(deviceModel);
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export enum DeviceType {
WASHER = 201,
WASHER_NEW = 221,
WASH_TOWER = 222,
WASH_TOWER_2 = 223,
DRYER = 202,
STYLER = 203,
DISHWASHER = 204,
Expand Down

0 comments on commit 8229b94

Please sign in to comment.