-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMMM-HS3_device_value.js
120 lines (96 loc) · 3.17 KB
/
MMM-HS3_device_value.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
/* Magic Mirror Module: HS3_device_value
*
* By Per Olav Eide Svendsen
* MIT Licensed.
*
* Based on MMM-backlog by Stefan Krause http://yawns.de
*/
Module.register('MMM-HS3_device_value',{
defaults: {
units: config.units,
animationSpeed: 1000,
updateInterval: 1000 * 60 * 15, //update every 15 min
refreshInterval: 1000 * 60 * 15, //refresh every 15 min
timeFormat: config.timeFormat,
lang: config.language,
initialLoadDelay: 0, // 0 seconds delay
retryDelay: 2500,
},
// Define required scripts.
getScripts: function() {
return ["moment.js"];
},
// Define requird styles
getStyles: function() {
return ["MMM-HS3_device_value.css"];
},
start: function() {
Log.info('Starting module: ' + this.name);
this.loaded = false;
this.sendSocketNotification('CONFIG', this.config);
},
getDom: function() {
var wrapper = document.createElement("div");
if (!this.loaded) {
wrapper.innerHTML = this.translate('LOADING');
wrapper.className = "dimmed light small";
return wrapper;
}
if (!this.data) {
wrapper.innerHTML = "No data";
wrapper.className = "dimmed light small";
return wrapper;
}
//var myStringArray = ["Hello","World"];
//var arrayLength = myStringArray.length;
//for (var i = 0; i < arrayLength; i++) {
// alert(myStringArray[i]);
// //Do something
//}
//var i;
//for (i = 0; i < cars.length; i++) {
// text += cars[i] + "<br>";
//}
var content = document.createElement("div");
content.innerHTML = ""
datablocks = this.data.Devices.reverse()
for (var i = 0; i < datablocks.length; i++) {
var t = datablocks[i].status;
var d = this.config.description[i];
content.innerHTML += ("<span class=deviceDescription>" + d + "</span><span class=deviceValue>" + t + "</span><br />");
};
// content.innerHTML = "hei"
// content.innerHTML += "kdfvjf"
//
// for (var i = 0; i < 2; i++) {
// content.innerHTML += this.config.description[i]
// };
wrapper.appendChild(content);
return wrapper;
},
socketNotificationReceived: function(notification, payload) {
if (notification === "STARTED") {
this.updateDom();
}
else if (notification === "DATA") {
this.loaded = true;
this.processData(JSON.parse(payload));
this.updateDom();
}
},
/* processData(data)
* Uses the received data to set the various values.
*
* argument data object - tide information received form worldtides.info
*/
processData: function(data) {
if (!data) {
// Did not receive usable new data.
// Maybe this needs a better check?
return;
}
this.data = data;
this.loaded = true;
this.updateDom(this.config.animationSpeed);
}
});