-
Notifications
You must be signed in to change notification settings - Fork 2
/
MMM-octoprint.js
88 lines (75 loc) · 1.9 KB
/
MMM-octoprint.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
/* global Module */
/* Magic Mirror
* Module: MMM-octoprint
*
* By Ben Konsemüller
* MIT Licensed.
*/
Module.register("MMM-octoprint", {
defaults: {
endpoint: "",
apiKey: "",
updateInterval: 60000,
showThumbnail: false,
showLayerProgress: false,
thumbnailSize: 150,
hideDataOnStandby: true
},
// Store the data in an object.
displayData: {
printer_status: null,
eta: null,
thumbnails: [],
},
available: true,
loading: true,
requiresVersion: "2.1.0", // Required version of MagicMirror
start: function () {
Log.info(`Starting module: ${this.name}`);
this.sendSocketNotification("CONFIG", this.config);
},
socketNotificationReceived: function (notification, payload) {
switch (notification) {
case "PRINTER_STATUS":
this.displayData = payload;
this.available = true;
this.loading = false;
break;
case "HTTP_ERROR":
this.loading = false;
this.available = false;
break;
}
this.updateDom(this.config.animationSpeed);
},
getTemplate: function () {
return "templates\\mmm-octoprint.njk";
},
getTemplateData() {
const templateData = {
loading: this.loading,
config: this.config,
printer_status: this.loading ? null : this.displayData.printer_status,
job_status: this.loading ? null : this.displayData.job_status,
eta: this.loading ? null : this.displayData.eta,
thumbnail: this.loading ? null : this.displayData.thumbnail,
layer_information: this.loading ? null : this.displayData.layer_information,
available: this.available,
};
return templateData;
},
getScripts: function () {
return [];
},
getStyles: function () {
return [
"MMM-octoprint.css",
];
},
getTranslations: function () {
return {
en: "translations/en.json",
de: "translations/de.json",
};
},
});