From 01cd8bd94aee45226ce27c499e3a77870e10fc7d Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Thu, 15 Aug 2024 16:28:15 +0200 Subject: [PATCH 1/7] Expand range of socket power scaling setting --- app.json | 12 ++++++++++++ drivers/socket/driver.settings.compose.json | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/app.json b/app.json index f04fcdc3..44c24607 100644 --- a/app.json +++ b/app.json @@ -2900,6 +2900,18 @@ "label": { "en": "1/10" } + }, + { + "id": "2", + "label": { + "en": "1/100" + } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, diff --git a/drivers/socket/driver.settings.compose.json b/drivers/socket/driver.settings.compose.json index ed9cffa3..4482a055 100644 --- a/drivers/socket/driver.settings.compose.json +++ b/drivers/socket/driver.settings.compose.json @@ -71,6 +71,18 @@ "label": { "en": "1/10" } + }, + { + "id": "2", + "label": { + "en": "1/100" + } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, From a681e97f8c70ae1eaad0956a7585704f634dca7c Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Thu, 15 Aug 2024 16:56:26 +0200 Subject: [PATCH 2/7] Add detection of socket power scaling --- drivers/socket/driver.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/socket/driver.ts b/drivers/socket/driver.ts index d52e9aad..460d28cc 100644 --- a/drivers/socket/driver.ts +++ b/drivers/socket/driver.ts @@ -185,6 +185,23 @@ module.exports = class TuyaOAuth2DriverSocket extends TuyaOAuth2Driver { // TODO: USB sockets (?) + if (!specifications) { + return props; + } + + for (const specification of specifications.status) { + const tuyaCapability = specification.code; + const values = JSON.parse(specification.values); + + if (tuyaCapability === 'cur_power') { + if ([0, 1, 2, 3].includes(values.scale)) { + props.settings['power_scaling'] = `${values.scale}`; + } else { + this.error('Unsupported power scale:', values.scale); + } + } + } + return props; } }; From 383a4a9efd7da1502abcb9d023c32530ff5ed328 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Thu, 15 Aug 2024 17:14:26 +0200 Subject: [PATCH 3/7] Add heater values scaling --- app.json | 93 +++++++++++++++++++++ drivers/heater/device.ts | 20 +++-- drivers/heater/driver.settings.compose.json | 93 +++++++++++++++++++++ drivers/heater/driver.ts | 25 ++++-- 4 files changed, 220 insertions(+), 11 deletions(-) diff --git a/app.json b/app.json index 44c24607..f6ac4d7c 100644 --- a/app.json +++ b/app.json @@ -2296,6 +2296,99 @@ "en": "The Tuya specification of this device" }, "value": "" + }, + { + "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": "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": "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" + } + } + ] } ] }, diff --git a/drivers/heater/device.ts b/drivers/heater/device.ts index 96e8ff26..73af7877 100644 --- a/drivers/heater/device.ts +++ b/drivers/heater/device.ts @@ -30,11 +30,17 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } if (typeof status['temp_current'] === 'number') { - this.setCapabilityValue('measure_temperature', status['temp_current']).catch(this.error); + const scaleExp = Number.parseInt(this.getSetting('temp_current_scaling') ?? '0', 10); + const scale = 10 ** scaleExp; + const temp_current = status['temp_current'] / scale; + this.setCapabilityValue('measure_temperature', temp_current).catch(this.error); } if (typeof status['temp_set'] === 'number') { - this.setCapabilityValue('target_temperature', status['temp_set']).catch(this.error); + const scaleExp = Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10); + const scale = 10 ** scaleExp; + const temp_set = status['temp_set'] / scale; + this.setCapabilityValue('target_temperature', temp_set).catch(this.error); } if (typeof status['lock'] === 'boolean') { @@ -42,7 +48,9 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } if (typeof status['work_power'] === 'number') { - const cur_power = status['work_power'] / 10.0; + const scaleExp = Number.parseInt(this.getSetting('work_power_scaling') ?? '0', 10); + const scale = 10 ** scaleExp; + const cur_power = status['work_power'] / scale; this.setCapabilityValue('measure_power', cur_power).catch(this.error); } @@ -59,10 +67,12 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } async targetTemperatureCapabilityListener(value: number): Promise { - const limitedTemperature = Math.max(0, Math.min(Math.floor(value), 50)); + const scaleExp = Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10); + const scale = 10 ** scaleExp; + const temp_set = value * scale; await this.sendCommand({ code: 'temp_set', - value: limitedTemperature, + value: temp_set, }); } diff --git a/drivers/heater/driver.settings.compose.json b/drivers/heater/driver.settings.compose.json index dceebc0d..fc7ace47 100644 --- a/drivers/heater/driver.settings.compose.json +++ b/drivers/heater/driver.settings.compose.json @@ -1,5 +1,98 @@ [ { "$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": "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": "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" + } + } + ] } ] diff --git a/drivers/heater/driver.ts b/drivers/heater/driver.ts index 2a26b97b..f028c654 100644 --- a/drivers/heater/driver.ts +++ b/drivers/heater/driver.ts @@ -48,15 +48,28 @@ module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver { return props; } - for (const functionSpecification of specifications.functions) { - if (functionSpecification.code === 'temp_set') { - const tempSetSpecs = JSON.parse(functionSpecification.values); + for (const spec of specifications.status) { + const tuyaCapability = spec.code; + const values = JSON.parse(spec.values); + + if (tuyaCapability === 'temp_set') { + const scaleExp = values.scale ?? 0; + const scale = 10 ** scaleExp; + props.capabilitiesOptions['target_temperature'] = { - step: tempSetSpecs.step, - min: tempSetSpecs.min, - max: tempSetSpecs.max, + step: values.step / scale, + min: values.min / scale, + max: values.max / scale, }; } + + if (['temp_set', 'temp_current', 'work_power'].includes(tuyaCapability)) { + if ([0, 1, 2].includes(values.scale)) { + props.settings[`${tuyaCapability}_scaling`] = `${values.scale}`; + } else { + this.error(`Unsupported ${tuyaCapability} scale:`, values.scale); + } + } } return props; From b669e4e6c5713fc1c1682732b95df8d8730699b4 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Fri, 16 Aug 2024 13:07:28 +0200 Subject: [PATCH 4/7] Add additional value scaling to socket --- app.json | 74 +++++++++++++++++++++ drivers/socket/device.ts | 8 ++- drivers/socket/driver.settings.compose.json | 74 +++++++++++++++++++++ drivers/socket/driver.ts | 8 +++ 4 files changed, 161 insertions(+), 3 deletions(-) diff --git a/app.json b/app.json index f6ac4d7c..7d3f9ce0 100644 --- a/app.json +++ b/app.json @@ -3008,6 +3008,80 @@ } ] }, + { + "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" + } + } + ] + }, { "id": "deviceSpecification", "type": "label", diff --git a/drivers/socket/device.ts b/drivers/socket/device.ts index dcf2a60f..393b1784 100644 --- a/drivers/socket/device.ts +++ b/drivers/socket/device.ts @@ -77,18 +77,20 @@ export default class TuyaOAuth2DeviceSocket extends TuyaOAuth2Device { this.safeSetCapabilityValue('onoff', anySwitchOn).catch(this.error); if (typeof status['cur_power'] === 'number') { - const powerScaling = 10 ** parseFloat(this.getSetting('power_scaling') ?? '0'); + const powerScaling = 10.0 ** parseInt(this.getSetting('power_scaling') ?? '0'); const cur_power = status['cur_power'] / powerScaling; this.setCapabilityValue('measure_power', cur_power).catch(this.error); } if (typeof status['cur_voltage'] === 'number') { - const cur_voltage = status['cur_voltage'] / 10.0; + const scaling = 10.0 ** parseInt(this.getSetting('cur_voltage_scaling') ?? '0'); + const cur_voltage = status['cur_voltage'] / scaling; this.setCapabilityValue('measure_voltage', cur_voltage).catch(this.error); } if (typeof status['cur_current'] === 'number') { - const cur_current = status['cur_current'] / 1000.0; + const scaling = 10.0 ** parseInt(this.getSetting('cur_current_scaling') ?? '0'); + const cur_current = status['cur_current'] / scaling / 1000.0; // Additionally convert mA this.setCapabilityValue('measure_current', cur_current).catch(this.error); } diff --git a/drivers/socket/driver.settings.compose.json b/drivers/socket/driver.settings.compose.json index 4482a055..c0553f5f 100644 --- a/drivers/socket/driver.settings.compose.json +++ b/drivers/socket/driver.settings.compose.json @@ -86,6 +86,80 @@ } ] }, + { + "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" + } + } + ] + }, { "$extends": "deviceSpecification" } diff --git a/drivers/socket/driver.ts b/drivers/socket/driver.ts index 460d28cc..241c32c7 100644 --- a/drivers/socket/driver.ts +++ b/drivers/socket/driver.ts @@ -200,6 +200,14 @@ module.exports = class TuyaOAuth2DriverSocket extends TuyaOAuth2Driver { this.error('Unsupported power scale:', values.scale); } } + + if (['cur_current', 'cur_voltage'].includes(tuyaCapability)) { + if ([0, 1, 2, 3].includes(values.scale)) { + props.settings[`${tuyaCapability}_scaling`] = `${values.scale}`; + } else { + this.error(`Unsupported ${tuyaCapability} scale:`, values.scale); + } + } } return props; From c26b58754a881b56c7c8d0c9c43013d6432b4aad Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Fri, 16 Aug 2024 13:22:35 +0200 Subject: [PATCH 5/7] Fix socket setting handler --- drivers/socket/TuyaSocketConstants.ts | 3 +++ drivers/socket/device.ts | 22 +++++++++++++++++----- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/socket/TuyaSocketConstants.ts b/drivers/socket/TuyaSocketConstants.ts index fc3cf28a..61e84ddb 100644 --- a/drivers/socket/TuyaSocketConstants.ts +++ b/drivers/socket/TuyaSocketConstants.ts @@ -6,6 +6,9 @@ export const SOCKET_SETTING_LABELS = { export type HomeySocketSettings = { child_lock: boolean; relay_status: 'power_on' | 'power_off' | 'last'; + power_scaling: '0' | '1' | '2' | '3'; + cur_current_scaling: '0' | '1' | '2' | '3'; + cur_voltage_scaling: '0' | '1' | '2' | '3'; }; export type TuyaSocketSettings = { diff --git a/drivers/socket/device.ts b/drivers/socket/device.ts index 393b1784..aa6fee4e 100644 --- a/drivers/socket/device.ts +++ b/drivers/socket/device.ts @@ -147,11 +147,23 @@ export default class TuyaOAuth2DeviceSocket extends TuyaOAuth2Device { } async onSettings(event: SettingsEvent): Promise { - // Deep copy, since event is read-only - const mappedEvent: SettingsEvent = { ...event }; + // Only some settings need to be sent to the device + function filterTuyaChangedKeys(changedKeys: (keyof HomeySocketSettings)[]): (keyof TuyaSocketSettings)[] { + return changedKeys.filter(key => ['child_lock', 'relay_status'].includes(key)) as (keyof TuyaSocketSettings)[]; + } + + const tuyaSettingsEvent: SettingsEvent = { + oldSettings: { + ...event.oldSettings, + }, + newSettings: { + ...event.newSettings, + }, + changedKeys: filterTuyaChangedKeys(event.changedKeys), + }; if (this.getStoreValue('tuya_category') === 'tdq') { - const mappedNewSettings = { ...mappedEvent.newSettings }; + const mappedNewSettings = { ...tuyaSettingsEvent.newSettings }; // Remap the relay_status switch (mappedNewSettings['relay_status']) { @@ -166,10 +178,10 @@ export default class TuyaOAuth2DeviceSocket extends TuyaOAuth2Device { break; } - mappedEvent.newSettings = mappedNewSettings; + tuyaSettingsEvent.newSettings = mappedNewSettings; } - return await TuyaOAuth2Util.onSettings(this, mappedEvent, SOCKET_SETTING_LABELS); + return await TuyaOAuth2Util.onSettings(this, tuyaSettingsEvent, SOCKET_SETTING_LABELS); } } From e3724598d8e5da86e24239d736f23d3609f8e7b3 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Fri, 16 Aug 2024 13:38:10 +0200 Subject: [PATCH 6/7] Neaten heater settings --- app.json | 18 ++++++++++++++++++ drivers/heater/TuyaHeaterConstants.ts | 8 ++++++++ drivers/heater/driver.settings.compose.json | 18 ++++++++++++++++++ drivers/heater/driver.ts | 2 +- 4 files changed, 45 insertions(+), 1 deletion(-) diff --git a/app.json b/app.json index 7d3f9ce0..4a7ab9ac 100644 --- a/app.json +++ b/app.json @@ -2325,6 +2325,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, @@ -2356,6 +2362,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, @@ -2387,6 +2399,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] } diff --git a/drivers/heater/TuyaHeaterConstants.ts b/drivers/heater/TuyaHeaterConstants.ts index 2c2c6a8e..281f6144 100644 --- a/drivers/heater/TuyaHeaterConstants.ts +++ b/drivers/heater/TuyaHeaterConstants.ts @@ -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; diff --git a/drivers/heater/driver.settings.compose.json b/drivers/heater/driver.settings.compose.json index fc7ace47..2d4abe5f 100644 --- a/drivers/heater/driver.settings.compose.json +++ b/drivers/heater/driver.settings.compose.json @@ -30,6 +30,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, @@ -61,6 +67,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] }, @@ -92,6 +104,12 @@ "label": { "en": "1/100" } + }, + { + "id": "3", + "label": { + "en": "1/1000" + } } ] } diff --git a/drivers/heater/driver.ts b/drivers/heater/driver.ts index f028c654..2ea4d545 100644 --- a/drivers/heater/driver.ts +++ b/drivers/heater/driver.ts @@ -64,7 +64,7 @@ module.exports = class TuyaOAuth2DriverHeater extends TuyaOAuth2Driver { } if (['temp_set', 'temp_current', 'work_power'].includes(tuyaCapability)) { - if ([0, 1, 2].includes(values.scale)) { + if ([0, 1, 2, 3].includes(values.scale)) { props.settings[`${tuyaCapability}_scaling`] = `${values.scale}`; } else { this.error(`Unsupported ${tuyaCapability} scale:`, values.scale); From 2bd269875a63dc94c3a570467b375214fa469730 Mon Sep 17 00:00:00 2001 From: Joost Loohuis Date: Fri, 16 Aug 2024 15:01:40 +0200 Subject: [PATCH 7/7] Neaten scaling calculation --- drivers/heater/device.ts | 24 ++++++++---------------- drivers/socket/device.ts | 14 ++++++-------- 2 files changed, 14 insertions(+), 24 deletions(-) diff --git a/drivers/heater/device.ts b/drivers/heater/device.ts index 73af7877..c1fe3382 100644 --- a/drivers/heater/device.ts +++ b/drivers/heater/device.ts @@ -30,17 +30,13 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } if (typeof status['temp_current'] === 'number') { - const scaleExp = Number.parseInt(this.getSetting('temp_current_scaling') ?? '0', 10); - const scale = 10 ** scaleExp; - const temp_current = status['temp_current'] / scale; - this.setCapabilityValue('measure_temperature', 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') { - const scaleExp = Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10); - const scale = 10 ** scaleExp; - const temp_set = status['temp_set'] / scale; - this.setCapabilityValue('target_temperature', 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') { @@ -48,10 +44,8 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } if (typeof status['work_power'] === 'number') { - const scaleExp = Number.parseInt(this.getSetting('work_power_scaling') ?? '0', 10); - const scale = 10 ** scaleExp; - const cur_power = status['work_power'] / scale; - 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') { @@ -67,12 +61,10 @@ module.exports = class TuyaOAuth2DeviceHeater extends TuyaOAuth2Device { } async targetTemperatureCapabilityListener(value: number): Promise { - const scaleExp = Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10); - const scale = 10 ** scaleExp; - const temp_set = value * scale; + const scaling = 10.0 ** Number.parseInt(this.getSetting('temp_set_scaling') ?? '0', 10); await this.sendCommand({ code: 'temp_set', - value: temp_set, + value: value * scaling, }); } diff --git a/drivers/socket/device.ts b/drivers/socket/device.ts index aa6fee4e..34d96c31 100644 --- a/drivers/socket/device.ts +++ b/drivers/socket/device.ts @@ -77,21 +77,19 @@ export default class TuyaOAuth2DeviceSocket extends TuyaOAuth2Device { this.safeSetCapabilityValue('onoff', anySwitchOn).catch(this.error); if (typeof status['cur_power'] === 'number') { - const powerScaling = 10.0 ** parseInt(this.getSetting('power_scaling') ?? '0'); - const cur_power = status['cur_power'] / powerScaling; - this.setCapabilityValue('measure_power', cur_power).catch(this.error); + const scaling = 10.0 ** parseInt(this.getSetting('power_scaling') ?? '0'); + this.setCapabilityValue('measure_power', status['cur_power'] / scaling).catch(this.error); } if (typeof status['cur_voltage'] === 'number') { const scaling = 10.0 ** parseInt(this.getSetting('cur_voltage_scaling') ?? '0'); - const cur_voltage = status['cur_voltage'] / scaling; - this.setCapabilityValue('measure_voltage', cur_voltage).catch(this.error); + this.setCapabilityValue('measure_voltage', status['cur_voltage'] / scaling).catch(this.error); } if (typeof status['cur_current'] === 'number') { - const scaling = 10.0 ** parseInt(this.getSetting('cur_current_scaling') ?? '0'); - const cur_current = status['cur_current'] / scaling / 1000.0; // Additionally convert mA - this.setCapabilityValue('measure_current', cur_current).catch(this.error); + // Additionally convert mA + const scaling = 1000.0 * 10.0 ** parseInt(this.getSetting('cur_current_scaling') ?? '0'); + this.setCapabilityValue('measure_current', status['cur_current'] / scaling).catch(this.error); } if (status['child_lock'] !== undefined) {