Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return new Promise((res, rej) => {
hue.nupnpSearch((err, result) => {
if (err) {
log.error('An error occurred fetching bridges from Hue: %s', err)
return rej(err);
}
// Get the first bridge
const bridge = result.length ? result[0] : {}
if (!bridge.id) {
log.error('No bridges found!');
return rej('No bridges found');
}
log.info('Found bridge: %s (IP: %s)', bridge.id, bridge.ipaddress)
res(bridge)
})
})
api.lights()
.then(displayResult)
.done();
/*
// Using a promise
api.registerUser(hostname, null, 'dshjdksaskhjd')
.then(displayUserResult)
.fail(displayError)
.done();
// --------------------------
// Using a promise
*/
hue.nupnpSearch().then(displayBridges).done();
api.config().then(displayResult).done();
api.config(function(err, config) {
})
server.get('/bridges/discover', async (req, res) => {
const timeout = 2000; // 2 seconds
hue.nupnpSearch(timeout).then((bridges) => {
res.json(bridges);
}).fail((err) => {
res.status(400).json(err);
}).done();
});
listBridges(print) {
return hue
.nupnpSearch()
.then(bridges => {
if (print) {
bridges.forEach(b => console.log(b.ipaddress));
}
return bridges;
}, () => Util.exit('No bridge found'));
}
setupBridge(ip = null, force = false) {
const bridge = Util.config.get('bridge');
if (bridge && Util.config.get('user') && !force) {
console.log(`Bridge configured at ${bridge}`);
return Promise.resolve();
}
return hue
.nupnpSearch()
.then(bridges => {
const bridge = ip ? bridges.find(b => b.ipaddress === ip) : bridges[0];
if (bridge !== null) {
Util.config.set('bridge', bridge.ipaddress);
console.log(`Hue bridge found at ${bridge.ipaddress}`);
return this.bridge;
}
return Promise.reject();
})
.catch(() => {
if (ip) {
Util.config.set('bridge', ip);
console.log(`Forced Hue bridge at ${ip}`);
return this.bridge;
}
const init = () => {
Hue.nupnpSearch().then(bridges => {
if (bridges.length > 0 ) {
if (bridges.length == 1) {
return bridges[0].ipaddress
} else {
console.log('\n')
console.log(chalk.cyan(`${bridges.length} Hue Bridge(s) Found:\n`))
bridges.map((b,i) => console.log(chalk.yellow(`${i+1}: ${b.name || ''} ${b.ipaddress} \n`)))
prompt.start()
return prompt.get(schema, (err, result) => {
return bridges[result.bridgeNumber - 1].ipaddress
})
}
}
}).then(host => {
const hue = new Hue.HueApi()
return createUser(host)
function find_hue_bridge() {
var hue = require("node-hue-api");
hue.nupnpSearch(function(err, result) {
console.log("find_hue_bridge",result);
if (err) throw err;
found_bridge = false;
for (var i = 0; i < device_array.length; i++) {
if (device_array[i].id == result[0].id) {
console.log("bridge already exist, creating user...");
create_user(result[0]);
found_bridge = true;
}
}
if (found_bridge == false) {
console.log("new bridge, creating user...");
device_array.push(result[0]);
store_device_object(result[0])
create_user(result[0]);
}
function find_hue_bridge() {
var hue = require("node-hue-api");
hue.nupnpSearch(function(err, result) {
console.log("find_hue_bridge",result);
if (err) throw err;
found_bridge = false;
for (var i = 0; i < device_array.length; i++) {
if (device_array[i].id == result[0].id) {
console.log("bridge already exist, creating user...");
create_user(result[0]);
found_bridge = true;
}
}
if (found_bridge == false) {
console.log("new bridge, creating user...");
device_array.push(result[0]);
database.store_device(result[0])
create_user(result[0]);
}