Merge e96c65c0bc6a4bc711d34a3d5497546d13e4c12b into d782a5afb67840492e5bb64b3444fd5877d6fa7e

This commit is contained in:
Kerber 2015-09-08 20:25:09 +00:00
commit 4efcbb1909

View File

@ -20,17 +20,34 @@ module.exports = function(RED) {
function WemoOut(n) { function WemoOut(n) {
RED.nodes.createNode(this,n); RED.nodes.createNode(this,n);
this.ipaddr = n.ipaddr; this.devices = [];
this.wemoSwitch = new Wemo(n.ipaddr); if (n.ipaddr) {
this.ipaddr = n.ipaddr;
this.devices[this.ipaddr] = new Wemo(n.ipaddr);
}
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg) {
var state = 0; if (msg != null) {
if ( msg.payload == 1 || msg.payload === true || msg.payload == "on" ) { state = 1; } var device;
node.wemoSwitch.setBinaryState(state, function(err, result) { if (msg.ipaddr) {
if (err) { node.warn(err); } if (!this.devices[msg.ipaddr]) {
//else { node.log(result); } this.devices[msg.ipaddr]=new Wemo(msg.ipaddr);
}); }
device=this.devices[msg.ipaddr];
}
else if (this.ipaddr) {
device=this.devices[this.ipaddr];
}
if (device) {
var state = 0;
if ( msg.payload == 1 || msg.payload === true || msg.payload == "on" ) { state = 1; }
device.setBinaryState(state, function(err, result) {
if (err) { node.warn(err); }
//else { node.log(result); }
});
}
}
}); });
} }
RED.nodes.registerType("wemo out",WemoOut); RED.nodes.registerType("wemo out",WemoOut);