forked from MichMich/mmm-systemtemperature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmmm-systemtemperature.js
45 lines (36 loc) · 1.23 KB
/
mmm-systemtemperature.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
Module.register("mmm-systemtemperature",{
defaults: {
prependString: 'System temperature: ',
updateInterval: 5000,
animationSpeed: 0,
unit: 'c'
},
start: function() {
this.temperature = 'fetching ...';
this.sendSocketNotification('CONFIG', this.config);
},
socketNotificationReceived: function(notification, payload) {
if (notification === 'TEMPERATURE') {
this.temperature = payload;
this.updateDom(this.config.animationSpeed);
}
},
// Override dom generator.
getDom: function() {
var wrapper = document.createElement("div");
// Do unit any conversions
if(this.temperature!='fetching ...' && this.config.unit.toLowerCase()!='c') {
if(this.config.unit.toLowerCase()=='f')
this.temperature = parseFloat(this.temperature) * 9 / 5 + 32;
else if(this.config.unit.toLowerCase()=='k')
this.temperature = parseFloat(this.temperature) - 273.15;
// Round off the temperature to 2 decimal places
this.temperature = Math.round(parseFloat(this.temperature*100))/100;
}
// Append ° + unit
if(this.temperature!='fetching ...')
this.temperature += '°'+this.config.unit.toUpperCase();
wrapper.innerHTML = this.config.prependString + this.temperature;
return wrapper;
}
});