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 4 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
14 changes: 8 additions & 6 deletions drivers/heater/TuyaHeaterConstants.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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 */,
} as const;
44 changes: 35 additions & 9 deletions drivers/heater/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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 +45,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 +57,10 @@ 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);
}
}

async onOffCapabilityListener(value: boolean): Promise<void> {
Expand All @@ -67,16 +79,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,
});
}
}
};
5 changes: 4 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