-
Notifications
You must be signed in to change notification settings - Fork 20
/
cli.js
55 lines (47 loc) · 1.37 KB
/
cli.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
53
54
55
'use strict';
const Lifx = require('./src/lifx').Client;
const client = new Lifx();
client.on('error', function(err) {
console.log('LIFX error:\n' + err.stack);
client.destroy();
});
client.on('message', function(msg, rinfo) {
if (typeof msg.type === 'string') {
// Known packages send by the lights as broadcast
switch (msg.type) {
case 'echoResponse':
case 'getOwner':
case 'stateOwner':
case 'getGroup':
case 'getVersion':
case 'stateGroup':
case 'getLocation':
case 'stateLocation':
case 'stateTemperature':
console.log(msg, ' from ' + rinfo.address);
break;
default:
break;
}
} else {
// Unknown message type
console.log(msg, ' from ' + rinfo.address);
}
});
client.on('light-new', function(light) {
console.log('New light found. ID:' + light.id + ', IP:' + light.address + ':' + light.port);
});
client.on('light-online', function(light) {
console.log('Light back online. ID:' + light.id + ', IP:' + light.address + ':' + light.port);
});
client.on('light-offline', function(light) {
console.log('Light offline. ID:' + light.id + ', IP:' + light.address + ':' + light.port);
});
client.on('listening', function() {
const address = client.address();
console.log(
'Started LIFX listening on ' +
address.address + ':' + address.port + '\n'
);
});
client.init();