forked from jannekalliola/MMM-BMWConnected
-
Notifications
You must be signed in to change notification settings - Fork 0
/
node_helper.js
41 lines (30 loc) · 1.14 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
var NodeHelper = require("node_helper");
const spawn = require("child_process").spawn;
module.exports = NodeHelper.create({
start: function () {
console.log("Starting node_helper for module: " + this.name);
this.bmwInfo = {};
this.config = {};
},
socketNotificationReceived: function (notification, payload) {
var self = this;
var vin = payload.vin;
if (notification == "MMM-MYBMW-CONFIG") {
self.config[vin] = payload;
self.bmwInfo[vin] = null;
} else if (notification == "MMM-MYBMW-GET") {
const config = self.config[vin];
const pythonProcess = spawn('python3',["modules/MMM-MyBMW/getMyBMWData.py", config.email, config.password, config.vin, config.region]);
pythonProcess.stdout.on('data', (data) => {
self.bmwInfo[vin] = JSON.parse(data);
self.sendResponse(payload);
});
pythonProcess.stderr.on('data', (data) => {
console.error(`bimmer_connected error: ${data}`);
});
}
},
sendResponse: function (payload) {
this.sendSocketNotification("MMM-MYBMW-RESPONSE" + payload.instanceId, this.bmwInfo[payload.vin]);
},
});