-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathnode_helper.js
More file actions
26 lines (20 loc) · 799 Bytes
/
Copy pathnode_helper.js
File metadata and controls
26 lines (20 loc) · 799 Bytes
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
var request = require('request');
var NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start: function() {
console.log("Starting node helper: " + this.name);
},
socketNotificationReceived: function(notification, payload) {
var self = this;
console.log("Notification: " + notification + " Payload: " + payload);
if(notification === "GET_SOLAR") {
var enlightenUrl = payload.config.url + payload.config.systemId + "/summary?&key=" + payload.config.apiKey + "&user_id=" + payload.config.userId;
request(enlightenUrl, function (error, response, body) {
if (!error && response.statusCode == 200) {
var jsonData = JSON.parse(body);
self.sendSocketNotification("SOLAR_DATA", jsonData);
}
});
}
},
});