Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (err) throw err;
var lights_discovered = JSON.stringify(lights, null, 2);
msg2 = { topic:node.topic, payload: { ipaddress:this.gw_ipaddress, lights:lights_discovered} };
node.send(msg2);
});
});
}
else {
//set the lamp status
//first locate the Hue gateway:
hue.locateBridges(function(err, result) {
var msg2 = {};
msg2.topic = this.topic;
if (err) throw err;
if(result[0]==null) {
msg2.payload="No Philips Hue Bridge located! Nothing to be done.";
console.log("No Philips Hue Bridge located!");
node.send(msg2);
}
else {
//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);
this.on("input", function(msg){
var myMsg = msg;
//set the lamp status
if (this.gw_ipaddress) {
setLights(node, myMsg);
} else {
//first locate the Hue gateway:
hue.locateBridges(function(err, result) {
if (err) { throw err; }
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found
this.gw_ipaddress = result[0].ipaddress;
setLights(node, myMsg);
}
else {
//bridge not found:
var msg = {};
msg.payload = "Bridge not found!";
node.send(msg);
}
this.on("input", function(msg){
//start with detecting the IP address of the Hue gateway in the local network:
hue.locateBridges(function(err, result) {
var msg = {};
if (err) { throw err; }
//check for found bridges
if(result[0]!=null) {
//save the IP address of the 1st bridge found
this.gw_ipaddress = result[0].ipaddress;
msg.payload = this.gw_ipaddress;
//get light info:
var api = new HueApi(this.gw_ipaddress, node.username);
api.lights(function(err, lights) {
var msg2 = {};
if (err) { throw err; }
var lights_discovered = JSON.stringify(lights, null, 2);
msg2.topic = "Lights";
msg2.payload = lights_discovered;
this.on("input", function(msg){
//set the lamp status
//first locate the Hue gateway:
hue.locateBridges(function(err, result) {
var msg2 = {};
msg2.topic = this.topic;
if (err) throw err;
//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();
var status;