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 heater of Large Home Appliances #152

Merged
merged 22 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
9 changes: 9 additions & 0 deletions .homeycompose/capabilities/fault.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"type": "string",
"title": {
"en": "Status"
},
"getable": true,
bogguard marked this conversation as resolved.
Show resolved Hide resolved
"setable": false,
"uiComponent": "sensor"
}
9 changes: 9 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,15 @@
"uiComponent": "button",
"icon": "assets/capabilities/eco.svg"
},
"fault": {
"type": "string",
"title": {
"en": "Status"
},
"getable": true,
bogguard marked this conversation as resolved.
Show resolved Hide resolved
"setable": false,
"uiComponent": "sensor"
},
"ptz_control_horizontal": {
"type": "enum",
"title": {
Expand Down
8 changes: 8 additions & 0 deletions drivers/heater/TuyaHeaterConstants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
export const HEATER_CAPABILITIES_MAPPING = {
/* Large and small appliances */
switch: 'onoff',
temp_set: 'target_temperature',
temp_current: 'measure_temperature',

/* small appliances */
lock: 'child_lock',
work_power: 'measure_power',
mode_eco: 'eco_mode',

/* large appliances */
child_lock: 'child_lock',
eco: 'eco_mode',
fault: 'fault',
} as const;
55 changes: 47 additions & 8 deletions drivers/heater/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
this.setCapabilityValue('child_lock', status['lock']).catch(this.error);
}

if (typeof status['child_lock'] === 'boolean') {
this.setCapabilityValue('child_lock', status['child_lock']).catch(this.error);
}

if (typeof status['work_power'] === 'number') {
const cur_power = status['work_power'] / 10.0;
this.setCapabilityValue('measure_power', cur_power).catch(this.error);
Expand All @@ -49,6 +53,27 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
if (typeof status['mode_eco'] === 'boolean') {
this.setCapabilityValue('eco_mode', status['mode_eco']).catch(this.error);
}

if (typeof status['eco'] === 'boolean') {
this.setCapabilityValue('eco_mode', status['eco']).catch(this.error);
}

if (typeof status['fault'] === 'number') {
const fault = status['fault'];
const faults = [];

const faultOptions = this.getCapabilityOptions('fault').values;
bogguard marked this conversation as resolved.
Show resolved Hide resolved

for (let i = 0; i < faultOptions.length; i++) {
if (fault & (1 << i)) {
faults.push(faultOptions[i]);
}
}

const faultString = faults.join(', ');

this.setCapabilityValue('fault', faults.length === 0 ? 'OK' : faultString).catch(this.error);
}
}

async onOffCapabilityListener(value: boolean): Promise<void> {
Expand All @@ -67,16 +92,30 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
}

async childLockCapabilityListener(value: boolean): Promise<void> {
await this.sendCommand({
code: 'lock',
value: value,
});
if (this.hasTuyaCapability('lock')) {
await this.sendCommand({
code: 'lock',
value: value,
});
} else if (this.hasTuyaCapability('child_lock')) {
await this.sendCommand({
code: 'child_lock',
value: value,
});
}
}

async ecoModeCapabilityListener(value: boolean): Promise<void> {
await this.sendCommand({
code: 'mode_eco',
value: value,
});
if (this.hasTuyaCapability('eco')) {
await this.sendCommand({
code: 'eco',
value: value,
});
} else if (this.hasTuyaCapability('mode_eco')) {
await this.sendCommand({
code: 'mode_eco',
value: value,
});
}
}
};
14 changes: 13 additions & 1 deletion drivers/heater/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ type DeviceArgs = { device: TuyaOAuth2Device };
type ValueArgs = { value: unknown };

module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver {
TUYA_DEVICE_CATEGORIES = [DEVICE_CATEGORIES.SMALL_HOME_APPLIANCES.HEATER] as const;
TUYA_DEVICE_CATEGORIES = [
DEVICE_CATEGORIES.SMALL_HOME_APPLIANCES.HEATER,
DEVICE_CATEGORIES.LARGE_HOME_APPLIANCES.HEATER,
] as const;

async onInit(): Promise<void> {
await super.onInit();
Expand Down Expand Up @@ -52,6 +55,15 @@ module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver {
max: tempSetSpecs.max,
};
}

for (const statusSpecification of specification.status) {
if (statusSpecification.code === 'fault') {
const faultSpecs = JSON.parse(statusSpecification.values);
this.log('Fault specs: ' + JSON.stringify(faultSpecs));
props.capabilitiesOptions['fault'] = {
values: [...faultSpecs.label],
};
}
bogguard marked this conversation as resolved.
Show resolved Hide resolved
}

return props;
Expand Down