-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
71 lines (62 loc) · 1.94 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/* Magic Mirror
*
* Node Helper for MMM-AutelisPentair module
*
* Earle Lowe [email protected]
* Apache License
*/
const NodeHelper = require('node_helper');
const request = require('request');
const xml2js = require('xml2js');
var parser = new xml2js.Parser();
parser.on("error", function(err) { console.log("Parser error", err); } );
module.exports = NodeHelper.create({
start: function() {
console.log("Starting module: " + this.name);
},
getPoolData: function() {
var url = "http://" + this.config.username + ":" + this.config.password + "@" + this.config.hostname + "/status.xml";
request({
url: url,
method: 'GET',
headers: {
'User-Agent': 'MagicMirror/1.0'
}
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var self=this;
parser.parseString(body, function(err, result) {
self.sendSocketNotification("POOL_DATA", result) ;
});
}
});
},
getPumpData: function() {
var url = "http://" + this.config.username + ":" + this.config.password + "@" + this.config.hostname + "/pumps.xml";
request({
url: url,
method: 'GET',
headers: {
'User-Agent': 'MagicMirror/1.0'
}
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
var self=this;
parser.parseString(body, function(err, result) {
self.sendSocketNotification("PUMP_DATA", result);
});
}
});
},
getData: function() {
this.getPoolData();
this.getPumpData();
},
socketNotificationReceived: function(notification, payload) {
if (notification === "CONFIG") {
this.config = payload;
} else if (notification === "GET_DATA") {
this.getData();
}
}
});