-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-SystemMonitor.js
95 lines (77 loc) · 1.94 KB
/
MMM-SystemMonitor.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
/* global Module */
/* Magic Mirror
* Module: MMM-SystemMonitor
*
* By Ben Konsemüller
* MIT Licensed.
*/
Module.register("MMM-SystemMonitor", {
defaults: {
updateInterval: 60000,
cpuThermalZone: 0,
units: config.units,
},
loading: true,
displayData: {
cpu_temp: null,
available_memory: null,
uptime: null,
available_space: null,
},
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function () {
Log.info(`Starting module: ${this.name}`);
this.addFilters();
this.sendSocketNotification("CONFIG", this.config);
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case "SYSTEM_MONITOR_DATA":
this.loading = false;
this.displayData = payload;
}
this.updateDom(this.config.animationSpeed);
},
getTemplate: function () {
return "templates\\MMM-SystemMonitor.njk";
},
getTemplateData() {
const templateData = {
data: this.displayData,
loading: this.loading
};
return templateData;
},
getScripts: function () {
return [];
},
getStyles: function () {
return [
"MMM-SystemMonitor.css",
];
},
addFilters() {
const env = this.nunjucksEnvironment();
env.addFilter("uptime", this.uptimeFormat.bind(this));
env.addFilter("convertTemperature", this.convertTemperature.bind(this));
},
uptimeFormat(uptimeInSeconds) {
return moment.utc(1000 * uptimeInSeconds).format('HH[h] mm[m] ss[s]');
},
convertTemperature(temperature) {
switch(this.config.units) {
case "metric":
return `${Math.round(temperature / 1000)}°C`;
case "imperial":
return `${Math.round(((temperature * 1.8) + 32) / 1000)}°F`;
default:
return `${Math.round(temperature / 1000)}°C`;
}
},
getTranslations: function () {
return {
en: "translations/en.json",
de: "translations/de.json",
};
},
});