forked from gberg927/MMM-DisneyWaitTimes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-ThemeParkWaitTimes.js
127 lines (107 loc) · 3.57 KB
/
MMM-ThemeParkWaitTimes.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
Module.register("MMM-ThemeParkWaitTimes", {
defaults: {
updateInterval: 10 * 60 * 1000,
futureHours: true,
},
getScripts: function () {
return ["moment.js"];
},
getStyles: function () {
return ["style.css"];
},
getHeader: function () {
var headerDiv = document.createElement("div");
headerDiv.innerHTML = this.data.header;
var timeSpan = document.createElement("div");
timeSpan.className = "parkTime";
if (this.openingTime != null && this.closingTime != null) {
timeSpan.innerHTML = " " + this.openingTime + " - " + this.closingTime;
}
headerDiv.appendChild(timeSpan);
if (this.futureHours != null && this.config.futureHours) {
var hoursTable = document.createElement("table");
hoursTable.className += "hours";
var hoursRow = document.createElement("tr");
hoursTable.appendChild(hoursRow);
const d = new Date();
for (var i = 0; i < 5; i++) {
var hoursCell = document.createElement("td");
hoursCell.className += "day" + ((d.getDay() + i + 1) % 7);
hoursRow.appendChild(hoursCell);
hoursCell.innerHTML = this.futureHours[i];
}
headerDiv.appendChild(hoursTable);
}
return headerDiv.innerHTML;
},
start: function () {
Log.info("Starting module: " + this.name);
const self = this;
this.rides = [];
this.openingTime;
this.closingTime;
this.futureHours;
this.errorMessage;
setInterval(function () {
self.processWaitTimes();
}, this.config.updateInterval);
this.processWaitTimes();
},
getDom: function () {
var table = document.createElement("table");
table.className = "small";
if (this.errorMessage) {
var row = document.createElement("tr");
row.className += "row";
table.appendChild(row);
var nameCell = document.createElement("td");
nameCell.className = "error";
nameCell.innerHTML = this.errorMessage;
row.appendChild(nameCell);
} else {
for (var i = 0, ride; (ride = this.rides[i++]); ) {
var row = document.createElement("tr");
row.className += "row";
table.appendChild(row);
var nameCell = document.createElement("td");
nameCell.className = "bright title";
nameCell.innerHTML = ride.name;
row.appendChild(nameCell);
var timeCell = document.createElement("td");
timeCell.className = "bright title light time";
if (ride.status == "CLOSED") {
timeCell.innerHTML = "closed";
} else if (ride.status == "DOWN") {
timeCell.innerHTML = "down";
} else if (ride.status == "REFURBISHMENT") {
timeCell.innerHTML = "refurb";
} else {
timeCell.innerHTML = ride.waitTime;
}
row.appendChild(timeCell);
}
}
return table;
},
socketNotificationReceived: function (notification, payload) {
console.log("n: " + notification);
if (notification === "POPULATE_WAIT_TIMES_" + this.config.park.entity) {
this.rides = payload.waitTimes;
this.updateDom();
} else if (
notification ===
"POPULATE_OPENING_TIMES_" + this.config.park.entity
) {
this.openingTime = payload.openingTime;
this.closingTime = payload.closingTime;
this.futureHours = payload.futureHours;
this.updateDom();
} else if (notification === "ERROR_" + this.config.park.entity) {
this.errorMessage = payload.errorMessage;
this.updateDom();
}
},
processWaitTimes: function () {
this.sendSocketNotification("GET_WAIT_TIMES", this.config.park);
},
});