forked from kymeyer/MMM-daikin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MMM-DaikinAirbase.js
163 lines (143 loc) · 4.61 KB
/
MMM-DaikinAirbase.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* global Module */
/* MagicMirror²
* Module: MMM-DaikinAirbase
*
* By Matt Thurling
* (Forked from MMM-Daikin made by Kyrill Meyer)
* MIT Licensed.
*/
Module.register("MMM-DaikinAirbase", {
defaults: {
ipAddress: "DaikinAirbase",
refreshInterval: 1000 * 60 * 1, // 1 minute
animationSpeed: 1 * 1000, // 1 seconds
},
fanRateValue: {
"0": "FAN_AUTO",
"1": "FAN_LOW",
"3": "FAN_MID",
"5": "FAN_HIGH",
"1a": "FAN_LOW_AUTO",
"3a": "FAN_MID_AUTO",
"5a": "FAN_HIGH_AUTO",
},
icons: {
"status-off": "fa-toggle-off",
"status-on": "fa-toggle-on",
"mode-fan": "fa-retweet",
"mode-heat": "fa-sun",
"mode-cool": "fa-snowflake",
"mode-auto": "fa-font",
"mode-dehumidify": "fa-droplet-slash",
"fan-speed": "fa-fan",
"outdoor-temp": "fa-cloud-sun",
"indoor-temp": "fa-thermometer-half",
"target-temp": "fa-crosshairs",
},
start () {
Log.info(`Starting module: ${this.name}`);
this.loaded = false;
this.stats = {};
this.getDaikinAirbaseStats();
const self = this;
setInterval(() => {
self.getDaikinAirbaseStats();
self.updateDom();
}, this.config.refreshInterval);
},
getDaikinAirbaseStats () {
Log.info("MMM-DaikinAirbase: getting stats");
this.sendSocketNotification(
"GET_DAIKIN_AIRBASE_STATS",
this.config
);
},
getDom () {
if (this.error) {
return this.renderError();
}
if (!this.loaded) {
return this.renderLoading();
}
return this.renderStats();
},
renderError () {
const wrapper = document.createElement("div");
wrapper.className = "dimmed light small";
wrapper.innerHTML = this.error;
return wrapper;
},
renderLoading () {
const wrapper = document.createElement("div");
wrapper.className = "dimmed light small";
wrapper.innerHTML = this.translate("LOADING");
return wrapper;
},
renderStats () {
const wrapper = document.createElement("table");
wrapper.className = "small";
wrapper.innerHTML = `
<tr>
<td class="name">${this.stats.name}</td>
${this.renderPower()}
${this.renderMode()}
${this.renderItem("fan-speed", this.translate(this.fanRateValue[this.stats.fanRate]), !this.stats.power)}
</tr>
<tr>
<td/>
${this.renderItem("outdoor-temp", `${this.stats.outdoorTemperature}°`)}
${this.renderItem("indoor-temp", `${this.stats.indoorTemperature}°`)}
${this.renderItem("target-temp", `${this.stats.targetTemperature}°`, !this.stats.power)}
</tr>
`;
return wrapper;
},
renderItem (iconToUse, value, dimmed) {
return `
<td class="bin title ${dimmed ? "dimmed" : "bright"}">
<i class="fas ${this.icons[iconToUse]}"></i> ${value}
</td>
`;
},
renderPower () {
if (this.stats.power !== "0") {
return this.renderItem("status-on", this.translate("ON"), !this.stats.power);
}
return this.renderItem("status-off", this.translate("OFF"), !this.stats.power);
},
renderMode () {
switch (this.stats.mode) {
case "0":
return this.renderItem("mode-fan", this.translate("FAN"), !this.stats.power);
case "1":
return this.renderItem("mode-heat", this.translate("HEAT"), !this.stats.power);
case "2":
return this.renderItem("mode-cool", this.translate("COOL"), !this.stats.power);
case "3":
return this.renderItem("mode-auto", this.translate("AUTO"), !this.stats.power);
case "7":
return this.renderItem("mode-dehumidify", this.translate("DEHUM"), !this.stats.power);
}
},
socketNotificationReceived (notification, payload) {
switch (notification) {
case "DAIKIN_AIRBASE_STATS":
this.error = "";
this.loaded = true;
this.stats = payload;
break;
case "DAIKIN_AIRBASE_ERROR":
this.error = payload;
break;
}
this.updateDom(this.config.animationSpeed);
},
getScripts () {
return [];
},
getTranslations () {
return {
en: "translations/en.json"
};
}
});