Skip to content

Commit

Permalink
* (Apollon77) Respect min/max when calculating the value for byOn wit…
Browse files Browse the repository at this point in the history
…h % values
  • Loading branch information
Apollon77 committed Mar 8, 2022
1 parent 6203da2 commit 3fd8cc5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
13 changes: 7 additions & 6 deletions lib/alexaSmartHomeV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion lib/googleHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
}
});
Expand Down

0 comments on commit 3fd8cc5

Please sign in to comment.