MMM-MyCovid19/MMM-MyCovid19.js
Sebastian Mark 741d2d1838 FIX: XMLHttpRequest blocked by CORS policy
* move http query to `node_helper`
* replace `XMLHttpRequest` by `node-fetch`
* implement SocketNotifications
2021-09-08 09:43:25 +02:00

69 lines
1.6 KiB
JavaScript

/* Magic Mirror
* Module: MMM-covid19
*
* Author: Sebastian Mark
* CC-BY-SA (https://creativecommons.org/licenses/by-sa/4.0/deed.de)
* for civil use only
*/
Module.register("MMM-MyCovid19", {
defaults: {
region: "Bonn",
updateInterval: 3 * 60 * 60 * 1000, // 3h
fadeSpeed: 0,
showHeader: true,
appendLocationNameToHeader: true,
},
cases: {
new7: "N/A",
new7_100k: "N/A",
active: "N/A",
total: "N/A",
death: "N/A",
cured: "N/A",
ts: "N/A",
},
start: function() {
// init module and set update intervall
var self = this
Log.log(self.name + ' is started!');
self.sendSocketNotification("{{MODULE_NAME}}-get_cases", self.config.region);
setInterval(function() {
self.sendSocketNotification("{{MODULE_NAME}}-get_cases", self.config.region);
self.updateDom(self.config.fadeSpeed);
}, self.config.updateInterval);
},
getHeader: function() {
// set module header
if (this.config.showHeader) {
this.data.header = "COVID-19 Daten";
if (this.config.appendLocationNameToHeader) {
this.data.header += " für " + this.config.region;
}
}
return this.data.header;
},
getStyles: function () {
// load custom css for module
return ["MMM-MyCovid19.css"];
},
getTemplate: function () {
// load template for layout
return 'MMM-MyCovid19.njk';
},
getTemplateData: function () {
// pass variables to template
return { cases: this.cases }
},
socketNotificationReceived: function(notification, payload) {
// receive cases from node_helper
this.cases = payload;
this.updateDom(this.config.fadeSpeed);
},
});