-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-EnphaseEnvoy.js
152 lines (124 loc) · 4.15 KB
/
MMM-EnphaseEnvoy.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
/* Module */
/* Magic Mirror
* Module: MMM-EnphaseEnvoy
*
* By Earle Lowe elowe@elowe.com
* Apache Licensed.
*/
Module.register("MMM-EnphaseEnvoy",{
defaults: {
hostname: "",
initialLoadDelay: 0,
updateInterval: 30 * 60 * 1000, // every 30 minutes
},
// Define start sequence.
start: function() {
this.loaded = false;
this.enphaseData = null;
this.sendSocketNotification("CONFIG", this.config);
this.scheduleUpdate(this.config.initialLoadDelay);
},
getStyles: function() {
return ['font-awesome.css', "MMM-EnphaseEnvoy.css"];
},
getData: function() {
this.sendSocketNotification("GET_DATA");
},
socketNotificationReceived: function(notification, payload) {
if (notification === "DATA") {
this.enphaseData = JSON.parse(payload);
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;
}
if (this.enphaseData)
{
currentUnit = this.enphaseData[2];
todayUnit = this.enphaseData[4];
weekUnit = this.enphaseData[6];
lifeUnit = this.enphaseData[8];
currentString = this.enphaseData[1] + " " + currentUnit + "W";
todayString = this.enphaseData[3] + " " + weekUnit + "Wh";
weekString = this.enphaseData[5] + " " + weekUnit + "Wh";
lifeString = this.enphaseData[7] + " " + lifeUnit + "Wh";
var table = document.createElement("TABLE");
table.className = "table";
var imgDiv = document.createElement("div");
var img = document.createElement("img");
img.src = "/modules/MMM-EnphaseEnvoy/solar_white.png";
var sTitle = document.createElement("p");
sTitle.innerHTML = "Solar PV";
sTitle.className += " header thin normal";
imgDiv.appendChild(img);
imgDiv.appendChild(sTitle);
var divider = document.createElement("hr");
divider.className += " dimmed";
wrapper.appendChild(imgDiv);
wrapper.appendChild(divider);
var currenttr = document.createElement("tr");
table.appendChild(currenttr);
var currentl = document.createElement("td");
var currentr = document.createElement("td");
currentl.className += " title medium light bright";
currentr.className += " data medium light normal";
currentl.innerHTML = "Current Power:";
currentr.innerHTML = currentString;
currenttr.appendChild(currentl);
currenttr.appendChild(currentr);
var todaytr = document.createElement("tr");
table.appendChild(todaytr);
var todayl = document.createElement("td");
var todayr = document.createElement("td");
todayl.className += " title medium light bright";
todayr.className += " data medium light normal";
todayl.innerHTML = "Today:";
todayr.innerHTML = todayString;
todaytr.appendChild(todayl);
todaytr.appendChild(todayr);
var weektr = document.createElement("tr");
table.appendChild(weektr);
var weekl = document.createElement("td");
var weekr = document.createElement("td");
weekl.className += " title medium light bright";
weekr.className += " data medium light normal";
weekl.innerHTML = "This Week:";
weekr.innerHTML = weekString;
weektr.appendChild(weekl);
weektr.appendChild(weekr);
var lifetr = document.createElement("tr");
table.appendChild(lifetr);
var lifel = document.createElement("td");
var lifer = document.createElement("td");
lifel.className += " title medium light bright";
lifer.className += " data medium light normal";
lifel.innerHTML = "Lifetime:";
lifer.innerHTML = lifeString;
lifetr.appendChild(lifel);
lifetr.appendChild(lifer);
wrapper.appendChild(table);
}
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);
},
});