-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-PVoutput.js
112 lines (97 loc) · 2.65 KB
/
MMM-PVoutput.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
/* global Module */
/* Magic Mirror
* Module: MMM-PVoutput
*
* By Martin van Es
* MIT Licensed.
*/
Module.register("MMM-PVoutput",{
// Define module defaults
defaults: {
width: 500,
height: 300,
lineWidth: 2,
showConsumption: false,
genLineColor: "#e0ffe0",
genFillColor: "rgba(100, 200, 100, 0.2)",
consLineColor: "#ffe0e0",
consFillColor: "rgba(200, 100, 100, 0.2)",
updateInterval: 300000,
maxPower: 2000,
},
// Override start method.
start: function() {
Log.log("Starting module: " + this.name);
this.payload = false;
this.sendSocketNotification("ADD_SYSTEM_ID", {
sid: this.config.sid,
apiKey: this.config.apiKey,
updateInterval: this.config.updateInterval,
});
},
// Define required scripts.
getScripts: function() {
return ["http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js", "jquery.sparkline.min.js"];
},
// Override socket notification handler.
socketNotificationReceived: function(notification, payload) {
if (notification == "ERROR") {
$("#curGe").html("");
$("#curGp").html("");
$("#sparkline").html(payload.error);
return;
}
$("#sparkline").sparkline(
payload.Gp, {
type: 'line',
width: this.config.width,
height: this.config.height,
lineColor: this.config.genLineColor,
fillColor: this.config.genFillColor,
spotColor: false,
minSpotColor: false,
maxSpotColor: false,
lineWidth: this.config.lineWidth,
chartRangeMin: 0,
chartRangeMax: this.config.maxPower,
});
if (this.config.showConsumption) {
$("#sparkline").sparkline(
payload.Cp, {
composite: true,
lineColor: "#ffe0e0",
fillColor: "rgba(200,100,100,0.2)",
spotColor: false,
minSpotColor: false,
maxSpotColor: false,
lineWidth: this.config.lineWidth,
chartRangeMin: 0,
chartRangeMax: this.config.maxPower,
});
};
$("#curGe").html((payload.curGe/1000).toFixed(1) + "kWh");
$("#curGp").html(payload.curGp + "W");
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("table");
wrapper.align = "center";
wrapper.style.cssText = "width: " + this.config.width + "px";
var currentRow = document.createElement("tr");
var curGe = document.createElement("td");
curGe.id = "curGe";
currentRow.appendChild(curGe);
var curGp = document.createElement("td");
curGp.id = "curGp";
currentRow.appendChild(curGp);
wrapper.appendChild(currentRow);
var graphRow = document.createElement("tr");
var graph = document.createElement("td");
graph.colSpan = 2;
graph.id = "sparkline";
graph.innerHTML = "No Data";
graphRow.appendChild(graph);
wrapper.appendChild(graphRow);
return wrapper;
}
});