-
Notifications
You must be signed in to change notification settings - Fork 0
/
MMM-OLYMPIC-MEDALS.js
84 lines (70 loc) · 2.15 KB
/
MMM-OLYMPIC-MEDALS.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
/* global Module Log moment config */
/* Magic Mirror
* Module: MMM-OLYMPIC-MEDALS
*
* By taylornoss https://github.com/taylornoss/MMM-OLYMPIC-MEDALS
* MIT Licensed.
*/
Module.register('MMM-OLYMPIC-MEDALS', {
defaults: {
season: 'summer', //summer or winter
year: '2024', //muse be valid for the season (e.g. summer divisible by 4, winter even but not divisible by 4)
reloadInterval: 60 * 60 * 1000, // every hour
tableSize: 'xsmall',
numOfRows: 10,
useAbbreviations: false
},
getTranslations() {
return {
en: 'translations/en.json',
};
},
getStyles() {
return ['font-awesome.css', 'MMM-OLYMPIC-MEDALS.css'];
},
getTemplate() {
return `templates/${this.name}.njk`;
},
getTemplateData() {
return {
loaded: this.loaded,
rows: this.rows,
config: this.config,
noData: this.noData,
configError: this.configError,
fns: { translate: this.translate.bind(this) }
};
},
start() {
Log.info(`Starting module: ${this.name}`);
this.loaded = false;
this.config.season = this.config.season.toLowerCase();
this.getData();
setInterval(() => {
console.log("Refreshing Olympics data...");
this.getData();
}, this.config.reloadInterval);
},
suspend() { },
resume() { },
getData() {
var sendData = {
id: this.identifier,
config: this.config
}
this.sendSocketNotification('GET-Olympic-Data', sendData);
},
socketNotificationReceived(notification, payload) {
if (notification === 'OLYMPIC-DATA' && payload.identifier === this.identifier) {
this.rows = payload.rows;
this.noData = (payload.header === "No Medals Data")
this.loaded = true;
this.configError = false;
this.updateDom();
}
else if (notification === 'OLYMPIC-CONFIG-ERROR' && payload === this.identifier) {
this.configError = true;
this.updateDom();
}
},
});