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 5 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
8 changes: 8 additions & 0 deletions .homeycompose/capabilities/fault.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "string",
"title": {
"en": "Status"
},
"getable": true,
bogguard marked this conversation as resolved.
Show resolved Hide resolved
"uiComponent": "sensor"
}
10 changes: 10 additions & 0 deletions .homeycompose/capabilities/mode.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": "enum",
"title": {
"en": "Mode"
},
"getable": true,
"setable": true,
"uiComponent": "picker",
"values": []
}
bogguard marked this conversation as resolved.
Show resolved Hide resolved
18 changes: 18 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2877,6 +2877,24 @@
"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
"uiComponent": "sensor"
},
"mode": {
"type": "enum",
"title": {
"en": "Mode"
},
"getable": true,
"setable": true,
"uiComponent": "picker",
"values": []
},
bogguard marked this conversation as resolved.
Show resolved Hide resolved
"ptz_control_horizontal": {
"type": "enum",
"title": {
Expand Down
16 changes: 10 additions & 6 deletions drivers/heater/TuyaHeaterConstants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
export const HEATER_CAPABILITIES_MAPPING = {
switch: 'onoff',
temp_set: 'target_temperature',
temp_current: 'measure_temperature',
lock: 'child_lock',
work_power: 'measure_power',
mode_eco: 'eco_mode',
switch: 'onoff' /* small and large appliances */,
temp_set: 'target_temperature' /* small and large appliances */,
temp_current: 'measure_temperature' /* small and large appliances */,
lock: 'child_lock' /* small appliances */,
child_lock: 'child_lock' /* large appliances */,
work_power: 'measure_power' /* small appliances */,
mode_eco: 'eco_mode' /* small appliances */,
eco: 'eco_mode' /* large appliances */,
//mode: 'mode' /* small and large appliances */, // commented out for now as it doesn't return the correct values from the Tuya specification
fault: 'fault' /* large appliances */,
bogguard marked this conversation as resolved.
Show resolved Hide resolved
} as const;
63 changes: 54 additions & 9 deletions drivers/heater/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
if (this.hasCapability('eco_mode')) {
this.registerCapabilityListener('eco_mode', value => this.ecoModeCapabilityListener(value));
}

/*if (this.hasCapability('mode')) {
this.registerCapabilityListener('mode', value =>
this.sendCommand({
code: 'mode',
value: value,
}),
);
}*/
bogguard marked this conversation as resolved.
Show resolved Hide resolved
}

async onTuyaStatus(status: TuyaStatus, changedStatusCodes: string[]): Promise<void> {
Expand All @@ -30,7 +39,11 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
}

if (typeof status['temp_current'] === 'number') {
this.setCapabilityValue('measure_temperature', status['temp_current']).catch(this.error);
if (this.getCapabilityOptions('target_temperature')?.max < 100) {
this.setCapabilityValue('measure_temperature', status['temp_current']).catch(this.error);
} else {
this.setCapabilityValue('measure_temperature', status['temp_current'] / 10.0).catch(this.error);
}
bogguard marked this conversation as resolved.
Show resolved Hide resolved
}

if (typeof status['temp_set'] === 'number') {
Expand All @@ -41,6 +54,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 +66,20 @@ 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') {
this.setCapabilityValue('fault', this.getCapabilityOptions('fault').values[status['fault'] - 1]).catch(
this.error,
);
bogguard marked this conversation as resolved.
Show resolved Hide resolved
}

/*if (typeof status['mode'] === 'string') {
this.setCapabilityValue('mode', status['mode']).catch(this.error);
}*/
bogguard marked this conversation as resolved.
Show resolved Hide resolved
}

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

async childLockCapabilityListener(value: boolean): Promise<void> {
await this.sendCommand({
code: 'lock',
value: value,
});
if (this.hasCapability('lock')) {
bogguard marked this conversation as resolved.
Show resolved Hide resolved
await this.sendCommand({
code: 'lock',
value: value,
});
} else if (this.hasCapability('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.hasCapability('eco')) {
await this.sendCommand({
code: 'eco',
value: value,
});
} else if (this.hasCapability('mode_eco')) {
await this.sendCommand({
code: 'mode_eco',
value: value,
});
}
}
};
24 changes: 23 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 @@ -43,6 +46,8 @@ module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver {
return props;
}

this.log('Specification: ', specification);

for (const functionSpecification of specification.functions) {
if (functionSpecification.code === 'temp_set') {
const tempSetSpecs = JSON.parse(functionSpecification.values);
Expand All @@ -52,6 +57,23 @@ module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver {
max: tempSetSpecs.max,
};
}

/*if (functionSpecification.code === 'mode') {
const modeSpecs = JSON.parse(functionSpecification.values);
props.capabilitiesOptions['mode'] = {
values: modeSpecs.range,
};
}*/
}
bogguard marked this conversation as resolved.
Show resolved Hide resolved

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: ['OK', ...faultSpecs.label] /** first state is OK state */,
};
}
}

return props;
Expand Down