forked from peter-murray/node-hue-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getGroupByType.js
73 lines (59 loc) · 1.74 KB
/
getGroupByType.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
const v3 = require('../../../index').v3;
// If using this code outside of this library the above should be replaced with
// const v3 = require('node-hue-api').v3;
const USERNAME = require('../../../test/support/testValues').username;
v3.discovery.nupnpSearch()
.then(searchResults => {
const host = searchResults[0].ipaddress;
return v3.api.createLocal(host).connect(USERNAME);
})
.then(api => {
const promises = [];
// Get and display Light Groups
promises.push(
api.groups.getLightGroups()
.then(displayGroups('LightGroups'))
);
// Get and display Luminaires
promises.push(
api.groups.getLuminaries()
.then(displayGroups('Luminaries'))
);
// Get and display LightSources
promises.push(
api.groups.getLightSources()
.then(displayGroups('LightSources'))
);
// Get and display Rooms
promises.push(
api.groups.getRooms()
.then(displayGroups('Rooms'))
);
// Get and display Zones
promises.push(
api.groups.getZones()
.then(displayGroups('Zones'))
);
// Get and display Entertainment
promises.push(
api.groups.getEntertainment()
.then(displayGroups('Entertainment'))
);
return Promise.all(promises);
})
;
function displayGroups(type) {
return function (groups) {
console.log('*************************************************************');
console.log(`Group Type: ${type}`);
if (groups && groups.length > 0) {
groups.forEach(group => {
console.log(group.toStringDetailed());
});
} else {
console.log('No matching groups in Hue Bridge');
}
console.log('*************************************************************');
};
}