mirror of
https://github.com/node-red/node-red-nodes.git
synced 2025-03-01 10:37:43 +00:00
Add ability to pass in wemo address as msg.ipaddr.
This commit is contained in:
parent
36ac3817a7
commit
e96c65c0bc
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user