-
Notifications
You must be signed in to change notification settings - Fork 4
/
node_helper.js
76 lines (63 loc) · 2.32 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
72
73
74
75
76
/* Magic Mirror
* Node Helper: MMM-Daikin
*
* By Kyrill Meyer
* MIT Licensed.
*/
const DaikinAC = require("daikin-controller");
const Log = require("logger");
const NodeHelper = require("node_helper");
module.exports = NodeHelper.create({
start() {
const self = this;
self.stats = {};
self.config = [];
Log.log(`Starting node helper: ${this.name}`);
},
socketNotificationReceived(notification, payload) {
const self = this;
if (notification === "START") {
self.config = payload;
}
if (notification === "MMM_DAIKIN_GETSTATS") {
self.handleStartNotification(payload);
}
},
handleStartNotification(payload) {
const self = this;
var options = {};
var daikin = new DaikinAC.DaikinAC(payload.ipAddress, options, function(err) {
if (err) {
Log.error("MMM-Daikin: Could not connect to A/C at "+payload.ipAddress+": "+err);
Object.assign(self.stats, {
ipAddress: payload.ipAddress,
lasterror: err,
});
self.sendSocketNotification("MMM_DAIKIN_ERROR", self.stats);
}
else {
Log.log("MMM-Daikin: Connection established to A/C at "+payload.ipAddress+"("+daikin.currentCommonBasicInfo.name+")...");
daikin.setUpdate(self.config.updateInterval, function(err) {
if (err) {
Log.error("MMM-Daikin: Could not get details for A/C at "+payload.ipAddress+"("+daikin.currentCommonBasicInfo.name+"): "+err);
}
else {
Object.assign(self.stats, {
ipAddress: payload.ipAddress,
name: daikin.currentCommonBasicInfo.name,
power: daikin.currentACControlInfo.power,
mode: daikin.currentACControlInfo.mode,
fandir: daikin.currentACControlInfo.fanDirection,
intemp: daikin.currentACSensorInfo.indoorTemperature,
outtemp: daikin.currentACSensorInfo.outdoorTemperature,
targettemp: daikin.currentACControlInfo.targetTemperature,
fanrate: daikin.currentACControlInfo.fanRate,
});
//Log.log("MMM-Daikin: Stats for A/C at "+payload.ipAddress+"("+daikin.currentCommonBasicInfo.name+")..."+JSON.stringify(self.stats));
self.sendSocketNotification('MMM_DAIKIN_STATS', self.stats);
}
});
}
});
}
});