mirror of
https://github.com/node-red/node-red-nodes.git
synced 2023-10-10 13:36:58 +02:00
added a no bridge check
This commit is contained in:
parent
b35ff010e2
commit
6474f5888d
@ -72,41 +72,50 @@ function HueNode(n) {
|
||||
var msg2 = {};
|
||||
msg2.topic = this.topic;
|
||||
if (err) throw err;
|
||||
//save the IP address of the 1st bridge found
|
||||
this.gw_ipaddress = result[0].ipaddress;
|
||||
//check for found bridges
|
||||
if(result[0]!=null) {
|
||||
//save the IP address of the 1st bridge found
|
||||
this.gw_ipaddress = result[0].ipaddress;
|
||||
|
||||
|
||||
//set light status
|
||||
var api = new HueApi(this.gw_ipaddress, node.username);
|
||||
var lightState = hue.lightState;
|
||||
var state = lightState.create();
|
||||
//set light status
|
||||
var api = new HueApi(this.gw_ipaddress, node.username);
|
||||
var lightState = hue.lightState;
|
||||
var state = lightState.create();
|
||||
|
||||
var status;
|
||||
if(msg.payload=="ALERT"){
|
||||
status = "ALERT";
|
||||
}
|
||||
else if(node.lamp_status=="ON" || msg.payload=="ON") status = "ON";
|
||||
else if(node.lamp_status=="OFF" || msg.payload=="OFF") status = "OFF";
|
||||
var status;
|
||||
if(msg.payload=="ALERT"){
|
||||
status = "ALERT";
|
||||
}
|
||||
else if(node.lamp_status=="ON" || msg.payload=="ON") status = "ON";
|
||||
else if(node.lamp_status=="OFF" || msg.payload=="OFF") status = "OFF";
|
||||
|
||||
|
||||
if(status=="ALERT") {
|
||||
api.setLightState(node.lamp_id, state.alert()).then(displayResult).fail(displayError).done();
|
||||
}
|
||||
else if(status=="ON") {
|
||||
if(node.color==null) {
|
||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(msg.topic).r,hexToRgb(msg.topic).g,hexToRgb(msg.topic).b)).then(displayResult).fail(displayError).done();
|
||||
if(status=="ALERT") {
|
||||
api.setLightState(node.lamp_id, state.alert()).then(displayResult).fail(displayError).done();
|
||||
}
|
||||
else if(status=="ON") {
|
||||
if(node.color==null) {
|
||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(msg.topic).r,hexToRgb(msg.topic).g,hexToRgb(msg.topic).b)).then(displayResult).fail(displayError).done();
|
||||
}
|
||||
else {
|
||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(node.color).r,hexToRgb(node.color).g,hexToRgb(node.color).b)).then(displayResult).fail(displayError).done();
|
||||
}
|
||||
}
|
||||
else {
|
||||
api.setLightState(node.lamp_id, state.on().rgb(hexToRgb(node.color).r,hexToRgb(node.color).g,hexToRgb(node.color).b)).then(displayResult).fail(displayError).done();
|
||||
api.setLightState(node.lamp_id, state.off()).then(displayResult).fail(displayError).done();
|
||||
}
|
||||
|
||||
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+status;
|
||||
node.send(msg2);
|
||||
}
|
||||
else {
|
||||
api.setLightState(node.lamp_id, state.off()).then(displayResult).fail(displayError).done();
|
||||
//bridge not found:
|
||||
var msg = {};
|
||||
msg.payload = "Bridge not found!";
|
||||
node.send(msg);
|
||||
}
|
||||
|
||||
msg2.payload = 'Light with ID: '+node.lamp_id+ ' was set to '+status;
|
||||
node.send(msg2);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user