From 3fd8cc543d0ef6ba92301d670c3f94d0ec0d2366 Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Tue, 8 Mar 2022 15:04:28 +0100 Subject: [PATCH] * (Apollon77) Respect min/max when calculating the value for byOn with % values --- README.md | 4 ++++ lib/alexaSmartHomeV2.js | 13 +++++++------ lib/googleHome.js | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index a5fe8e90..20750102 100644 --- a/README.md +++ b/README.md @@ -268,6 +268,10 @@ Following types are supported: --> ## Changelog + +### __WORK IN PROGRESS__ +* (Apollon77) Respect min/max when calculating the value for byOn with % values + ### 1.9.7 (2022-02-20) * (Apollon77) Fix crash case reported by Sentry (IOBROKER-IOT-3C) diff --git a/lib/alexaSmartHomeV2.js b/lib/alexaSmartHomeV2.js index e565c117..19007aa7 100644 --- a/lib/alexaSmartHomeV2.js +++ b/lib/alexaSmartHomeV2.js @@ -477,11 +477,10 @@ function AlexaSH2(adapter) { adapter.log.debug(`[ALEXA] Use stored ON value for "${id}": ${valuesON[id]}`); value = valuesON[id]; } else { - if (typeof obj.common.max !== 'undefined') { - value = byON ? parseFloat(byON) || obj.common.max : obj.common.max; - } else { - value = byON ? parseFloat(byON) || 100 : 100; - } + const min = typeof obj.common.min !== 'undefined' ? obj.common.min : 0; + const max = typeof obj.common.max !== 'undefined' ? obj.common.max : 100; + + value = byON ? Math.round(((parseFloat(byON) || 100) * (max - min) / 100) + min) : max; } } else { // if OFF @@ -498,6 +497,8 @@ function AlexaSH2(adapter) { // do not remember the minimum/off value if (state && state.val !== value) valuesON[id] = state.val; + adapter.log.debug(`[ALEXA] OFF Stored: Set "${id}" to ${value} and store old value "${id}"`); + adapter.setForeignState(id, value, err => { err && adapter.log.error(`[ALEXA] Cannot switch device: ${err}`); callback && callback(err); @@ -520,7 +521,7 @@ function AlexaSH2(adapter) { value = '#000000'; } } - adapter.log.debug('[ALEXA] Set "' + id + '" to ' + value); + adapter.log.debug(`[ALEXA] Set "${id}" to ${value}`); if (writeStates) { adapter.setState('smart.lastObjectID', id, true); diff --git a/lib/googleHome.js b/lib/googleHome.js index c7f7815b..88826612 100644 --- a/lib/googleHome.js +++ b/lib/googleHome.js @@ -2310,7 +2310,7 @@ class GoogleHome { errorMessage = error.message; } - this.adapter.log.error(`[GHOME] Cannot updateState: ${errorMessage}`); + this.adapter.log.error(`[GHOME] Cannot updateState: ${JSON.stringify(errorMessage)}`); this.adapter.log.debug(`[GHOME] ${JSON.stringify(json)}`); } });