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

Improve status scaling #158

Merged
merged 7 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
197 changes: 197 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,117 @@
"en": "The Tuya specification of this device"
},
"value": "<not available>"
},
{
"id": "temp_set_scaling",
"type": "dropdown",
"label": {
"en": "Target Temperature Scale"
},
"hint": {
"en": "By how much the temperature targeted by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "temp_current_scaling",
"type": "dropdown",
"label": {
"en": "Measured Temperature Scale"
},
"hint": {
"en": "By how much the temperature measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "work_power_scaling",
"type": "dropdown",
"label": {
"en": "Measured Power Scale"
},
"hint": {
"en": "By how much the power measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
}
]
},
Expand Down Expand Up @@ -2900,6 +3011,92 @@
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "cur_current_scaling",
"type": "dropdown",
"label": {
"en": "Current Measurement Scale"
},
"hint": {
"en": "By how much the current reported by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "cur_voltage_scaling",
"type": "dropdown",
"label": {
"en": "Voltage Measurement Scale"
},
"hint": {
"en": "By how much the voltage reported by the device is scaled."
},
"value": "1",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
Expand Down
8 changes: 8 additions & 0 deletions drivers/heater/TuyaHeaterConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,11 @@ export const HEATER_CAPABILITIES_MAPPING = {
work_power: 'measure_power',
mode_eco: 'eco_mode',
} as const;

export type HomeySocketSettings = {
temp_set_scaling: '0' | '1' | '2' | '3';
temp_current_scaling: '0' | '1' | '2' | '3';
work_power_scaling: '0' | '1' | '2' | '3';
};

export type TuyaSocketSettings = Record<string, never>;
14 changes: 8 additions & 6 deletions drivers/heater/device.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,22 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
}

if (typeof status['temp_current'] === 'number') {
this.setCapabilityValue('measure_temperature', status['temp_current']).catch(this.error);
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_current_scaling') ?? '0', 10);
this.setCapabilityValue('measure_temperature', status['temp_current'] / scaling).catch(this.error);
}

if (typeof status['temp_set'] === 'number') {
this.setCapabilityValue('target_temperature', status['temp_set']).catch(this.error);
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10);
this.setCapabilityValue('target_temperature', status['temp_set'] / scaling).catch(this.error);
}

if (typeof status['lock'] === 'boolean') {
this.setCapabilityValue('child_lock', status['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);
const scaling = 10.0 ** Number.parseInt(this.getSetting('work_power_scaling') ?? '0', 10);
this.setCapabilityValue('measure_power', status['work_power'] / scaling).catch(this.error);
}

if (typeof status['mode_eco'] === 'boolean') {
Expand All @@ -59,10 +61,10 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device {
}

async targetTemperatureCapabilityListener(value: number): Promise<void> {
const limitedTemperature = Math.max(0, Math.min(Math.floor(value), 50));
const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10);
await this.sendCommand({
code: 'temp_set',
value: limitedTemperature,
value: value * scaling,
});
}

Expand Down
111 changes: 111 additions & 0 deletions drivers/heater/driver.settings.compose.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,116 @@
[
{
"$extends": "deviceSpecification"
},
{
"id": "temp_set_scaling",
"type": "dropdown",
"label": {
"en": "Target Temperature Scale"
},
"hint": {
"en": "By how much the temperature targeted by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "temp_current_scaling",
"type": "dropdown",
"label": {
"en": "Measured Temperature Scale"
},
"hint": {
"en": "By how much the temperature measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
},
{
"id": "work_power_scaling",
"type": "dropdown",
"label": {
"en": "Measured Power Scale"
},
"hint": {
"en": "By how much the power measured by the device is scaled."
},
"value": "0",
"values": [
{
"id": "0",
"label": {
"en": "1"
}
},
{
"id": "1",
"label": {
"en": "1/10"
}
},
{
"id": "2",
"label": {
"en": "1/100"
}
},
{
"id": "3",
"label": {
"en": "1/1000"
}
}
]
}
]
Loading
Loading