-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMMM-PiTemp.js
55 lines (50 loc) · 1.34 KB
/
MMM-PiTemp.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
Module.register("MMM-PiTemp", {
defaults: {
tempUnit: "C",
freq: 60000,
high: 80,
low: 70,
highColor: "red",
lowColor: "green",
otherColor: "yellow",
label: "<i class='fab fa-raspberry-pi'></i>"
},
start: function() {
this.sendSocketNotification("get_temp");
},
getDom: function() {
var e = document.createElement("div")
e.id = "pi_temp"
return e
},
notificationReceived: function(notification, payload, sender) {
switch(notification) {
case "DOM_OBJECTS_CREATED":
var timer = setInterval(()=>{
this.sendSocketNotification("get_temp")
}, this.config.freq)
break
}
},
socketNotificationReceived: function(notification, payload) {
switch (notification) {
case "temperature":
var e = document.getElementById("pi_temp");
if (parseFloat(payload) <= this.config.low) {
e.style.color = this.config.lowColor;
} else if (parseFloat(payload) >= this.config.high) {
e.style.color = this.config.highColor;
} else {
e.style.color = this.config.otherColor;
}
var temp;
if (this.config.tempUnit === "C") {
temp = payload.toString() + "°C";
} else {
temp = (payload * (9 / 5) + 32).toFixed(1).toString() + "°F";
}
e.innerHTML = this.config.label + " " + temp;
break;
}
},
})