-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
39 lines (32 loc) · 1.03 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
"use strict";
/* Magic Mirror
* Node Helper: MMM-VartaESS
*
* By Beh (hello@beh.wtf)
* MIT Licensed.
*/
const NodeHelper = require("node_helper");
const VartaFetcher = require("./VartaFetcher").VartaFetcher;
module.exports = NodeHelper.create({
initialize: async function (config) {
if (typeof this.fetcher === "undefined") {
this.fetcher = new VartaFetcher(config);
this.fetcher.on("DATA", (data) => {
this.sendSocketNotification("MMM-VartaESS_DATA", data);
});
this.fetcher.on("ERROR", (error_string) => {
this.sendSocketNotification("MMM-VartaESS_ERROR", error_string);
});
this.fetcher.run();
this.sendSocketNotification("MMM-VartaESS_INITIALIZED");
}
},
stop: function () {
this.fetcher.disconnect();
},
socketNotificationReceived: function (notification, payload) {
if (notification === "MMM-VartaESS_INIT") {
this.initialize(payload);
}
},
});