-
Notifications
You must be signed in to change notification settings - Fork 5
/
MMM-Canteen.js
73 lines (59 loc) · 1.73 KB
/
MMM-Canteen.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
/* Magic Mirror
* Module: MMM-Canteen
*/
/* jshint esversion: 6 */
Module.register("MMM-Canteen", {
defaults: {
updateInterval: 10 * 60 * 1000, //10 minutes
canteen: 838,
status: "employees", //choose between ["employees", "students", "pupils", "others"]
truncate: 100,
switchTime: "16:00",
debug: false,
canteenName: "Kantine"
},
loading: true,
closed: false,
meals: [],
start: function() {
console.log("Starting module: " + this.name);
this.sendSocketNotification("CONFIG", this.config);
},
getStyles: function() {
return ["MMM-Canteen.css"];
},
getTemplate: function() {
return "MMM-Canteen.njk";
},
getTemplateData: function() {
this.log("Updating template data");
today: moment().format("DD MM.YYYY");
return {
today: (moment() < moment(this.config.switchTime, "HH:mm")) ? moment().format("DD.MM.YYYY") : moment().add(1, "days").format("DD.MM.YYYY"),
config: this.config,
loading: this.loading,
meals: this.meals,
closed: this.closed
};
},
socketNotificationReceived: function(notification, payload) {
Log.info("Socket Notification received: "+notification);
this.loading = false;
if (notification == "MEALS") {
if (payload.length) {
this.closed = false;
this.meals = payload;
this.log(this.meals);
}
} else if (notification == "CLOSED") {
this.log("Mensa hat heute geschlossen!");
this.closed = true;
}
this.updateDom(500);
},
log: function(msg) {
if (this.config && this.config.debug) {
Log.info(`${this.name}: ` + JSON.stringify(msg));
}
},
});