-
Notifications
You must be signed in to change notification settings - Fork 10
/
example.js
52 lines (44 loc) · 1.09 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
var hue = require('./lib/hue');
var loadBridge = function(host) {
hue.load({
"host" : host
});
hue.getUsername(function(err, result) {
if (err) {
console.log(err);
return;
}
turnOnLights(host, result.username);
});
};
var turnOnLights = function(host, username) {
hue.load({
"host" : host,
"key" : username
});
hue.lights(function(lights) {
for (var i in lights) {
if (lights.hasOwnProperty(i)) {
hue.change(lights[i].set({
"on" : true,
"rgb" : [
Math.random() * 256 >>> 0,
Math.random() * 256 >>> 0,
Math.random() * 256 >>> 0
]
}));
}
}
});
};
hue.nupnpDiscover(function(error, hosts) {
if (error) {
console.error(error);
return;
}
for (var i in hosts) {
if (hosts.hasOwnProperty(i)) {
loadBridge(hosts[i].internalipaddress);
}
}
});