Skip to content

Commit

Permalink
Merge pull request felixls#10 from juggledad/master
Browse files Browse the repository at this point in the history
Update smart-plug-bak.js
  • Loading branch information
mental-os authored Aug 11, 2018
2 parents 8e62d88 + f36e7e7 commit 1fb1d06
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions smart-plug.bak.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ module.exports = function(RED) {
node.on('input', function(msg) {
if (!node.isClientConnected()) return node.handleConnectionError('not reachable');
const EVENT_ACTIONS = ['getMeterEvents','getInfoEvents','getPowerUpdateEvents','getInUseEvents','getOnlineEvents'];
if(msg.payload == true||msg.payload == false) {
// test to see if user send a string "true" or "false" or "on" or "off" and change it to boolean true/false
if (typeof msg.payload === 'string' || msg.payload instanceof String) {
var msg_test = msg.payload.toUpperCase();
if(msg_test == 'TRUE'||msg_test == 'ON') {msg.payload = true;}
if(msg_test == 'FALSE'||msg_test == 'OFF') {msg.payload = false;}
}
if(msg.payload == true||msg.payload == false) {
node.deviceInstance.setPowerState(msg.payload).then(() => {node.sendDeviceSysInfo()})
.catch(error => {return node.handleConnectionError(error)});
} else if (msg.payload === 'getInfo') node.sendDeviceSysInfo();
Expand Down Expand Up @@ -224,4 +230,4 @@ module.exports = function(RED) {
.then(device => {res.end(device.model)})
.catch(error => {res.sendStatus(500).send(error.message)});
});
};
};

0 comments on commit 1fb1d06

Please sign in to comment.