Skip to content

Commit

Permalink
HWS activity send poweroff if payload is false, 'false', 0, '0' or 'off'
Browse files Browse the repository at this point in the history
  • Loading branch information
lopelex committed May 31, 2019
1 parent 19e3997 commit 32bd7fc
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion harmony/harmony.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,26 @@ module.exports = function(RED) {
}
RED.nodes.registerType('HWS command', HarmonySendCommand)


function toBoolean(value, defaultValue) {
if (typeof value == 'boolean' || value instanceof Boolean) {
return value;
}
if (typeof value == 'string' || value instanceof String) {
value = value.trim().toLowerCase();
if (value === 'false' ||
value === '0' ||
value === 'off'
) {
return false;
}
}
if (typeof value == 'number' || value instanceof Number) {
if (value === 0) {
return false;
}
}
return defaultValue;
}

function HarmonyActivity(config) {
var node = this;
Expand All @@ -78,6 +97,9 @@ module.exports = function(RED) {
if (!id) {
id = node.activity;
}
if (!toBoolean(msg.payload, true)) {
id = '-1'; //poweroff
}
node.server.hub.startActivity(id)
.then(res => {
if (!res.code || res.code != 200) {
Expand Down

0 comments on commit 32bd7fc

Please sign in to comment.