MMM-MyCovid19/MMM-MyCovid19.js

70 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2020-07-26 08:50:34 +00:00
/* 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", {
2020-07-26 08:50:34 +00:00
defaults: {
region: "Bonn",
updateInterval: 3 * 60 * 60 * 1000, // 3h
2020-07-26 08:50:34 +00:00
fadeSpeed: 0,
showHeader: true,
appendLocationNameToHeader: true,
},
cases: {
new7: "N/A",
2020-09-27 17:52:25 +00:00
new7_100k: "N/A",
2020-07-26 08:50:34 +00:00
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);
2020-07-26 08:50:34 +00:00
setInterval(function() {
self.sendSocketNotification("{{MODULE_NAME}}-get_cases", self.config.region);
self.updateDom(self.config.fadeSpeed);
}, self.config.updateInterval);
2020-07-26 08:50:34 +00:00
},
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"];
},
2020-07-26 08:50:34 +00:00
getTemplate: function () {
// load template for layout
return 'MMM-MyCovid19.njk';
},
2020-07-26 08:50:34 +00:00
getTemplateData: function () {
// pass variables to template
return { cases: this.cases }
2020-07-26 08:50:34 +00:00
},
socketNotificationReceived: function(notification, payload) {
// receive cases from node_helper
this.cases = payload;
this.updateDom(this.config.fadeSpeed);
2020-07-26 08:50:34 +00:00
},
});