-
Notifications
You must be signed in to change notification settings - Fork 3
/
node_helper.js
60 lines (50 loc) · 1.4 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
/* Magic Mirror
* Node Helper: MMM-UKMOWeatherWarnings
*
* By Malcolm Oakes https://github.com/maloakes
*
* MIT Licensed.
*/
const FeedMe = require("feedme")
const http = require("http")
const moment = require("moment")
const fs = require("fs")
var NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
// Subclass start method.
start: function() {
console.log("Started node_helper.js for MMM-UKMOWeatherWarnings.");
},
// Override socketNotificationReceived method.
/* socketNotificationReceived(notification, payload)
* This method is called when a socket notification arrives.
*
* argument notification string - The identifier of the noitication.
* argument payload mixed - The payload of the notification.
*/
socketNotificationReceived: function(notification, payload) {
if (notification === "MMM-UKMOWeatherWarnings-WARNINGS-REQ") {
this.warningsRequest(payload)
}
},
/*
* request for the warning message
* get the message from the feed
* notify the module
*/
warningsRequest: function(url) {
self = this
http.get(url, (res) => {
if (res.statusCode != 200) {
console.error(new Error(`status code ${res.statusCode}`))
return
}
var parser = new FeedMe(true)
res.pipe(parser)
parser.on("end", () => {
res = parser.done()
self.sendSocketNotification("MMM-UKMOWeatherWarnings-WARNINGS-RESULT", res);
})
})
},
});