-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode_helper.js
48 lines (39 loc) · 1.06 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
/* MiOSView Info */
/* Magic Mirror
* Module: MiOS Viewer
* By Nick Wootton
* MIT Licensed.
*/
var NodeHelper = require('node_helper');
var request = require('request');
module.exports = NodeHelper.create({
start: function () {
console.log('MMM-MiOSView helper started ...');
},
/* getVeraData()
* Requests new data from local vera devices
* Sends data back via socket on succesfull response.
*/
getVeraData: function(url,api_key) {
var self = this;
var retry = true;
var options = {
url: url,
headers: {
'Content-Type': 'application/json'
},
method: 'GET'
};
request(options, function(error, response, body) {
if(!error && response.statusCode == 200) {
self.sendSocketNotification('MiOS_DATA', {'data': JSON.parse(body), 'url': url});
}
});
},
//Subclass socketNotificationReceived received.
socketNotificationReceived: function(notification, payload) {
if (notification === 'GET_MiOSINFO') {
this.getVeraData(payload.url);
}
}
});