forked from michael5r/mmm-hue-lights
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
39 lines (30 loc) · 1.3 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
var NodeHelper = require('node_helper');
var axios = require('axios').default;
module.exports = NodeHelper.create({
start: function() {
console.log('Starting node_helper for module [' + this.name + ']');
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'MMM_HUE_LIGHTS_GET') {
var bridgeIp = payload.bridgeIp;
var user = payload.user;
var url = 'http://' + bridgeIp + '/api/' + user;
var self = this;
axios.get(url)
.then(function (res) {
if (res.status !== 200) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: ' + res.status);
} else {
if (res.data === {}) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: No Hue data was received.');
} else {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA', res.data);
}
}
})
.catch(function (err) {
self.sendSocketNotification('MMM_HUE_LIGHTS_DATA_ERROR', 'Hue API Error: ' + err);
});
}
}
});