Skip to content

Commit

Permalink
Add thermostat mode
Browse files Browse the repository at this point in the history
  • Loading branch information
JELoohuis committed Sep 18, 2024
1 parent ed7b195 commit f9f907b
Show file tree
Hide file tree
Showing 5 changed files with 180 additions and 2 deletions.
46 changes: 46 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -5161,6 +5161,52 @@
"nl": "Thermostaat"
},
"capabilitiesOptions": {
"thermostat_mode": {
"values": [
{
"id": "cold",
"title": {
"en": "Cold"
}
},
{
"id": "hot",
"title": {
"en": "Hot"
}
},
{
"id": "wind",
"title": {
"en": "Wind"
}
},
{
"id": "comfortable",
"title": {
"en": "Comfortable"
}
},
{
"id": "energy",
"title": {
"en": "Energy"
}
},
{
"id": "auto",
"title": {
"en": "Auto"
}
},
{
"id": "holiday",
"title": {
"en": "Holiday"
}
}
]
},
"legacy_fan_speed": {
"values": [
{
Expand Down
13 changes: 12 additions & 1 deletion drivers/thermostat/TuyaThermostatConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ export const THERMOSTAT_CAPABILITIES_MAPPING = {
window_state: 'open_window_sensor',
battery_percentage: 'measure_battery',
humidity: 'measure_humidity',
mode: 'thermostat_mode',
} as const;

export const THERMOSTAT_CAPABILITIES = {
read_write: ['switch', 'eco', 'child_lock', 'switch_vertical', 'switch_horizontal', 'sleep', 'frost', 'level'],
read_write: [
'switch',
'eco',
'child_lock',
'switch_vertical',
'switch_horizontal',
'sleep',
'frost',
'level',
'mode',
],
read_only: ['window_state', 'battery_percentage'],
read_scaled: ['temp_set', 'work_power', 'temp_current', 'humidity'],
setting: ['capacity_set', 'temp_correction', 'sensor_choose', 'backlight', 'backlight_enum', 'window_check'],
Expand Down
4 changes: 4 additions & 0 deletions drivers/thermostat/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ module.exports = class TuyaOAuth2DeviceThermostat extends TuyaOAuth2Device {
if (constIncludes(THERMOSTAT_CAPABILITIES.setting, tuyaCapability)) {
await this.safeSetSettingValue(tuyaCapability, value);
}

if (tuyaCapability === 'work_state' && !this.hasTuyaCapability('mode')) {
await this.safeSetCapabilityValue(homeyCapability, value);
}
}

for (const tuyaCapability of changed) {
Expand Down
46 changes: 46 additions & 0 deletions drivers/thermostat/driver.compose.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,52 @@
},
"capabilities": ["measure_temperature", "target_temperature"],
"capabilitiesOptions": {
"thermostat_mode": {
"values": [
{
"id": "cold",
"title": {
"en": "Cold"
}
},
{
"id": "hot",
"title": {
"en": "Hot"
}
},
{
"id": "wind",
"title": {
"en": "Wind"
}
},
{
"id": "comfortable",
"title": {
"en": "Comfortable"
}
},
{
"id": "energy",
"title": {
"en": "Energy"
}
},
{
"id": "auto",
"title": {
"en": "Auto"
}
},
{
"id": "holiday",
"title": {
"en": "Holiday"
}
}
]
},
"legacy_fan_speed": {
"values": [
{
Expand Down
73 changes: 72 additions & 1 deletion drivers/thermostat/driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,67 @@ module.exports = class TuyaOAuth2DriverThermostat extends TuyaOAuth2Driver {
): ListDeviceProperties {
const props = super.onTuyaPairListDeviceProperties(device, specifications, dataPoints);

let mode = false;
let work_state = false;

for (const status of device.status) {
const tuyaCapability = status.code;
const homeyCapability = getFromMap(THERMOSTAT_CAPABILITIES_MAPPING, tuyaCapability);

if (homeyCapability) {
props.store.tuya_capabilities.push(tuyaCapability);
props.capabilities.push(homeyCapability);
} else if (constIncludes(THERMOSTAT_CAPABILITIES.setting, tuyaCapability)) {
}

if (constIncludes(THERMOSTAT_CAPABILITIES.setting, tuyaCapability)) {
props.store.tuya_capabilities.push(tuyaCapability);
}

if (tuyaCapability === 'mode') {
mode = true;
}

if (tuyaCapability === 'work_state') {
work_state = true;
}
}

if (mode) {
work_state = false;
}

if (work_state) {
props.store.tuya_capabilities.push('work_state');
props.capabilities.push('thermostat_mode');
const values = [
'cold',
'hot',
'wind',
'comfortable',
'energy',
'auto',
'holiday',
'eco',
'manual',
'sleep',
'dry',
'program',
'floor_heat',
'auxiliary_heat',
].map(value => {
const capitalized = value.charAt(0).toUpperCase() + value.slice(1);
return {
id: value,
title: {
en: capitalized,
},
};
});

props.capabilitiesOptions['thermostat_mode'] = {
values: values,
setable: false,
};
}

if (!specifications || !specifications.status) {
Expand Down Expand Up @@ -73,6 +124,26 @@ module.exports = class TuyaOAuth2DriverThermostat extends TuyaOAuth2Driver {
this.error(`Unsupported ${tuyaCapability} scale:`, values.scale);
}
}

if (tuyaCapability === 'mode' || (work_state && tuyaCapability === 'work_state')) {
if (!values.range || values.range.length === 0) {
continue;
}

const modeOptions = (values.range as string[]).map(value => {
const capitalized = value.charAt(0).toUpperCase() + value.slice(1);
return {
id: value,
title: {
en: capitalized,
},
};
});

props.capabilitiesOptions['thermostat_mode'] = {
values: modeOptions,
};
}
}

return props;
Expand Down

0 comments on commit f9f907b

Please sign in to comment.