-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-AutelisPentair.js
158 lines (125 loc) · 4.06 KB
/
MMM-AutelisPentair.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
/* Module */
/* Magic Mirror
* Module: MMM-AutelisPentair
*
* By Earle Lowe [email protected]
* Apache Licensed.
*/
Module.register("MMM-AutelisPentair",{
// Default module config.
defaults: {
username: "",
password: "",
hostname: "",
initialLoadDelay: 0,
updateInterval: 10 * 60 * 1000, // every 10 minutes
},
// Define start sequence.
start: function() {
this.loaded = false;
this.poolData = null;
this.pumpData = null;
this.sendSocketNotification("CONFIG", this.config);
this.scheduleUpdate(this.config.initialLoadDelay);
},
getStyles: function() {
return ['font-awesome.css', "MMM-AutelisPentair.css"];
},
getData: function() {
Log.info("Getting Data");
this.sendSocketNotification("GET_DATA");
},
socketNotificationReceived: function(notification, payload) {
if (notification === "POOL_DATA") {
this.poolData = payload.response;
this.loaded = true;
this.updateDom();
} else if (notification === "PUMP_DATA") {
this.pumpData = payload.response;
this.loaded = true;
this.updateDom();
}
this.scheduleUpdate()
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = "Getting Data";
wrapper.className = "dimmed light small";
return wrapper;
}
wrapper.className = "MMM-AutelisPentair";
var large = document.createElement("div");
large.className = "medium light";
if (this.poolData) {
poolStatus = this.poolData.equipment[0].circuit6[0];
spaStatus = this.poolData.equipment[0].circuit1[0];
var poolString = "";
var poolTemp = document.createElement("span");
if (poolStatus === "1") {
poolTemp.className = "bright poolTemp";
poolString = "Pool is On: " + this.poolData.temp[0].pooltemp[0] + "°";
} else if (spaStatus === "1") {
poolTemp.className = "bright poolTemp";
spaString = "Spa is On" + this.poolData.temp[0].spatemp[0] + "°";
} else {
poolTemp.className = "dimmed poolTemp";
poolString = "Pool is Off";
}
poolTemp.innerHTML = poolString;
large.appendChild(poolTemp);
var htstatus = this.poolData.temp[0].htstatus[0];
if (poolStatus === "1" || spaStatus === "1") {
if (this.pumpData) {
// Add in Pump Speed
var toSplit = this.pumpData.pumps[0].pump1[0].split(",");
var pumpWatts = toSplit[0];
var pumpSpeed = toSplit[1];
var pumpInfo= document.createElement("div");
pumpInfo.className = "bright small pumpInfo";
pumpInfo.innerHTML = "Pump: " + pumpWatts + " Watts, " + pumpSpeed + " RPM";
large.appendChild(pumpInfo);
}
// Show Pool heater information
var heatInfo = document.createElement("div");
if (htstatus === "0") {
heatInfo.className = "dimmed small heatInfo";
heatInfo.innerHTML = "Heat is off";
} else if (htstatus === "12" || htstatus === "14") {
heatInfo.className = "bright small heatInfo";
heatInfo.innerHTML = "Heat is on: Solar";
} else if (htstatus === "10" || htstatus === "18") {
heatInfo.className = "bright small heatInfo";
heatInfo.innerHTML = "Heat is on";
}
large.appendChild(heatInfo);
}
var airsolTemp = document.createElement("div");
airsolTemp.className = "light medium airsolTemp";
large.appendChild(airsolTemp);
var airTemp = document.createElement("span");
airTemp.innerHTML = "Air: " + this.poolData.temp[0].airtemp[0] + "° ";
airsolTemp.appendChild(airTemp);
var solTemp = document.createElement("span");
solTemp.className = "solTemp";
solTemp.innerHTML = "Solar: " + this.poolData.temp[0].soltemp[0] + "°";
airsolTemp.appendChild(solTemp);
}
wrapper.appendChild(large);
return wrapper;
},
notificationReceived: function(notification, payload, sender) {
if (notification === "DOM_OBJECTS_CREATED") {
this.updateDom();
}
},
scheduleUpdate: function(delay) {
var nextLoad = this.config.updateInterval;
if (typeof delay !== "undefined" && delay >= 0) {
nextLoad = delay;
}
var self = this;
setTimeout(function() { self.getData(); }, nextLoad);
},
});