-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
49 lines (35 loc) · 1.46 KB
/
node_helper.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
var NodeHelper = require('node_helper')
var fetch = require('node-fetch')
module.exports = NodeHelper.create ({
requiresVersion: '2.22.0',
start: function() {
console.log('Starting node_helper for module: ' + this.name)
},
getLights: async function(payload) {
var url = "http://" + payload.bridgeip + "/api/" + payload.userid + "/" + payload.lightsOrGroups;
var response = await fetch(url)
if (!response.status == 200) {
console.error(`Error retrieving data: ${response.statusCode} ${response.statusText}`)
return;
}
var result = await response.json()
this.sendSocketNotification("lightsorgroups", result)
},
getGroups: async function(payload) {
var url = "http://" + payload.bridgeip + "/api/" + payload.userid + "/" + payload.lightsOrGroups;
var response = await fetch(url)
if (!response.status == 200) {
console.error(`Error retrieving data: ${response.statusCode} ${response.statusText}`)
return;
}
var result = await response.json()
this.sendSocketNotification("lightsorgroups", result)
},
socketNotificationReceived: function(notification, payload) {
if (notification === "huelights") {
this.getLights(payload)
} else if (notification === "huegroups") {
this.getGroups(payload)
}
}
})