Merge pull request #1996 from rejas/eslint_recommend

Update eslint config to use eslint:recommended
This commit is contained in:
Michael Teeuw 2020-04-23 10:23:40 +02:00 committed by GitHub
commit 3c54d4af15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 279 additions and 455 deletions

View File

@ -1,20 +1,10 @@
{ {
"rules": { "extends": "eslint:recommended",
"indent": ["error", "tab"],
"quotes": ["error", "double"],
"semi": ["error"],
"max-len": ["error", 250],
"curly": "error",
"camelcase": ["error", {"properties": "never"}],
"no-multiple-empty-lines": ["error", { "max": 1, "maxEOF": 1 }],
"no-multi-spaces": "error",
"no-trailing-spaces": ["error", {"ignoreComments": false }],
"no-irregular-whitespace": ["error"]
},
"env": { "env": {
"browser": true, "browser": true,
"node": true, "es6": true,
"es6": true "mocha": true,
"node": true
}, },
"parserOptions": { "parserOptions": {
"sourceType": "module", "sourceType": "module",
@ -22,5 +12,11 @@
"ecmaFeatures": { "ecmaFeatures": {
"globalReturn": true "globalReturn": true
} }
} },
"rules": {
"eqeqeq": "error",
"no-prototype-builtins": "off",
"no-undef": "off",
"no-unused-vars": "off"
}
} }

View File

@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Cleaned up alert module code - Cleaned up alert module code
- Cleaned up check_config code - Cleaned up check_config code
- Replaced grunt-based linters with their non-grunt equivalents - Replaced grunt-based linters with their non-grunt equivalents
- Switch to most of the eslint:recommended rules and fix warnings
### Deleted ### Deleted
- Removed truetype (ttf) fonts - Removed truetype (ttf) fonts

View File

@ -9,19 +9,19 @@
*/ */
var config = { var config = {
address: "localhost", // Address to listen on, can be: address: "localhost", // Address to listen on, can be:
// - "localhost", "127.0.0.1", "::1" to listen on loopback interface // - "localhost", "127.0.0.1", "::1" to listen on loopback interface
// - another specific IPv4/6 to listen on a specific interface // - another specific IPv4/6 to listen on a specific interface
// - "0.0.0.0", "::" to listen on any interface // - "0.0.0.0", "::" to listen on any interface
// Default, when address config is left out or empty, is "localhost" // Default, when address config is left out or empty, is "localhost"
port: 8080, port: 8080,
basePath: "/", // The URL path where MagicMirror is hosted. If you are using a Reverse proxy basePath: "/", // The URL path where MagicMirror is hosted. If you are using a Reverse proxy
// you must set the sub path here. basePath must end with a / // you must set the sub path here. basePath must end with a /
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], // Set [] to allow all IP addresses
// or add a specific IPv4 of 192.168.1.5 : // or add a specific IPv4 of 192.168.1.5 :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"], // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.1.5"],
// or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format : // or IPv4 range of 192.168.3.0 --> 192.168.3.15 use CIDR format :
// ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"], // ["127.0.0.1", "::ffff:127.0.0.1", "::1", "::ffff:192.168.3.0/28"],
useHttps: false, // Support HTTPS or not, default "false" will use HTTP useHttps: false, // Support HTTPS or not, default "false" will use HTTP
httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true httpsPrivateKey: "", // HTTPS private key path, only require when useHttps is true
@ -31,10 +31,10 @@ var config = {
timeFormat: 24, timeFormat: 24,
units: "metric", units: "metric",
// serverOnly: true/false/"local" , // serverOnly: true/false/"local" ,
// local for armv6l processors, default // local for armv6l processors, default
// starts serveronly and then starts chrome browser // starts serveronly and then starts chrome browser
// false, default for all NON-armv6l devices // false, default for all NON-armv6l devices
// true, force serveronly mode, because you want to.. no UI on this device // true, force serveronly mode, because you want to.. no UI on this device
modules: [ modules: [
{ {
@ -100,7 +100,6 @@ var config = {
} }
}, },
] ]
}; };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/

View File

@ -61,7 +61,7 @@ var App = function() {
// https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8 // https://forum.magicmirror.builders/topic/1456/test-suite-for-magicmirror/8
var configFilename = path.resolve(global.root_path + "/config/config.js"); var configFilename = path.resolve(global.root_path + "/config/config.js");
if (typeof(global.configuration_file) !== "undefined") { if (typeof(global.configuration_file) !== "undefined") {
configFilename = path.resolve(global.configuration_file); configFilename = path.resolve(global.configuration_file);
} }
try { try {

View File

@ -22,8 +22,8 @@
initializing = false; initializing = false;
// Make a copy of all prototype properties, to prevent reference issues. // Make a copy of all prototype properties, to prevent reference issues.
for (var name in prototype) { for (var p in prototype) {
prototype[name] = cloneObject(prototype[name]); prototype[p] = cloneObject(prototype[p]);
} }
// Copy the properties over onto the new prototype // Copy the properties over onto the new prototype

View File

@ -1,7 +1,7 @@
/* exported defaults */ /* exported defaults */
/* Magic Mirror /* Magic Mirror
* Config Defauls * Config Defaults
* *
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.

View File

@ -1,11 +1,11 @@
/* global config, vendor, MM, Log, Module */ /* global config, vendor, MM, Log, Module */
/* Magic Mirror /* Magic Mirror
* Module and File loaders. * Module and File loaders.
* *
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
var Loader = (function() { var Loader = (function() {
/* Create helper variables */ /* Create helper variables */

View File

@ -1,4 +1,3 @@
/* global console */
/* exported Log */ /* exported Log */
/* Magic Mirror /* Magic Mirror

View File

@ -1,4 +1,4 @@
/* global Log, Loader, Module, config, defaults */ /* global Log, Loader, Module, config, defaults */
/* Magic Mirror /* Magic Mirror
* Main System * Main System
@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
var MM = (function() { var MM = (function() {
var modules = []; var modules = [];
@ -344,6 +343,8 @@ var MM = (function() {
* Loads the core config and combines it with de system defaults. * Loads the core config and combines it with de system defaults.
*/ */
var loadConfig = function() { var loadConfig = function() {
// FIXME: Think about how to pass config around without breaking tests
/* eslint-disable */
if (typeof config === "undefined") { if (typeof config === "undefined") {
config = defaults; config = defaults;
Log.error("Config file is missing! Please create a config file."); Log.error("Config file is missing! Please create a config file.");
@ -351,6 +352,7 @@ var MM = (function() {
} }
config = Object.assign({}, defaults, config); config = Object.assign({}, defaults, config);
/* eslint-enable */
}; };
/* setSelectionMethodsForModules() /* setSelectionMethodsForModules()

View File

@ -1,4 +1,3 @@
/* global Log, Class, Loader, Class , MM */
/* exported Module */ /* exported Module */
/* Magic Mirror /* Magic Mirror

View File

@ -73,7 +73,7 @@ var Server = function(config, callback) {
configFile = "config/config.js"; configFile = "config/config.js";
if (typeof(global.configuration_file) !== "undefined") { if (typeof(global.configuration_file) !== "undefined") {
configFile = global.configuration_file; configFile = global.configuration_file;
} }
html = html.replace("#CONFIG_FILE#", configFile); html = html.replace("#CONFIG_FILE#", configFile);

View File

@ -1,5 +1,3 @@
/* exported Log */
/* Magic Mirror /* Magic Mirror
* Socket Connection * Socket Connection
* *

View File

@ -1,4 +1,5 @@
/* exported Translator */ /* exported Translator */
/* Magic Mirror /* Magic Mirror
* Translator (l10n) * Translator (l10n)
* *
@ -129,10 +130,10 @@ var Translator = (function() {
if(Object.prototype.toString.call(template) !== "[object String]") { if(Object.prototype.toString.call(template) !== "[object String]") {
return template; return template;
} }
if(variables.fallback && !template.match(new RegExp("\{.+\}"))) { if(variables.fallback && !template.match(new RegExp("{.+}"))) {
template = variables.fallback; template = variables.fallback;
} }
return template.replace(new RegExp("\{([^\}]+)\}", "g"), function(_unused, varName){ return template.replace(new RegExp("{([^}]+)}", "g"), function(_unused, varName){
return variables[varName] || "{"+varName+"}"; return variables[varName] || "{"+varName+"}";
}); });
} }

View File

@ -1,4 +1,5 @@
/* exported Utils */ /* exported Utils */
/* Magic Mirror /* Magic Mirror
* Utils * Utils
* *

View File

@ -6,7 +6,6 @@
* By Paul-Vincent Roll http://paulvincentroll.com * By Paul-Vincent Roll http://paulvincentroll.com
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("alert",{ Module.register("alert",{
defaults: { defaults: {
// scale|slide|genie|jelly|flip|bouncyflip|exploader // scale|slide|genie|jelly|flip|bouncyflip|exploader

View File

@ -10,7 +10,7 @@
* Copyright 2014, Codrops * Copyright 2014, Codrops
* http://www.codrops.com * http://www.codrops.com
*/ */
;(function(window) { (function(window) {
/** /**
* extend obj function * extend obj function

View File

@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("calendar", { Module.register("calendar", {
// Define module defaults // Define module defaults
@ -254,6 +253,8 @@ Module.register("calendar", {
titleWrapper.className = "title " + titleClass; titleWrapper.className = "title " + titleClass;
} }
var timeWrapper;
if(this.config.timeFormat === "dateheaders"){ if(this.config.timeFormat === "dateheaders"){
if (event.fullDayEvent) { if (event.fullDayEvent) {
@ -261,10 +262,8 @@ Module.register("calendar", {
titleWrapper.align = "left"; titleWrapper.align = "left";
} else { } else {
timeWrapper = document.createElement("td");
var timeClass = this.timeClassForUrl(event.url); timeWrapper.className = "time light " + this.timeClassForUrl(event.url);
var timeWrapper = document.createElement("td");
timeWrapper.className = "time light " + timeClass;
timeWrapper.align = "left"; timeWrapper.align = "left";
timeWrapper.style.paddingLeft = "2px"; timeWrapper.style.paddingLeft = "2px";
timeWrapper.innerHTML = moment(event.startDate, "x").format("LT"); timeWrapper.innerHTML = moment(event.startDate, "x").format("LT");
@ -274,7 +273,7 @@ Module.register("calendar", {
eventWrapper.appendChild(titleWrapper); eventWrapper.appendChild(titleWrapper);
} else { } else {
var timeWrapper = document.createElement("td"); timeWrapper = document.createElement("td");
eventWrapper.appendChild(titleWrapper); eventWrapper.appendChild(titleWrapper);
//console.log(event.today); //console.log(event.today);
@ -370,8 +369,7 @@ Module.register("calendar", {
} }
//timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll'); //timeWrapper.innerHTML += ' - '+ moment(event.startDate,'x').format('lll');
//console.log(event); //console.log(event);
var timeClass = this.timeClassForUrl(event.url); timeWrapper.className = "time light " + this.timeClassForUrl(event.url);
timeWrapper.className = "time light " + timeClass;
eventWrapper.appendChild(timeWrapper); eventWrapper.appendChild(timeWrapper);
} }
@ -424,15 +422,12 @@ Module.register("calendar", {
switch (timeFormat) { switch (timeFormat) {
case 12: { case 12: {
return { longDateFormat: {LT: "h:mm A"} }; return { longDateFormat: {LT: "h:mm A"} };
break;
} }
case 24: { case 24: {
return { longDateFormat: {LT: "HH:mm"} }; return { longDateFormat: {LT: "HH:mm"} };
break;
} }
default: { default: {
return { longDateFormat: {LT: moment.localeData().longDateFormat("LT")} }; return { longDateFormat: {LT: moment.localeData().longDateFormat("LT")} };
break;
} }
} }
}, },
@ -474,8 +469,8 @@ Module.register("calendar", {
} }
if(this.config.hidePrivate) { if(this.config.hidePrivate) {
if(event.class === "PRIVATE") { if(event.class === "PRIVATE") {
// do not add the current event, skip it // do not add the current event, skip it
continue; continue;
} }
} }
if(this.config.hideOngoing) { if(this.config.hideOngoing) {
@ -734,8 +729,8 @@ Module.register("calendar", {
var regParts = needle.match(/^\/(.+)\/([gim]*)$/); var regParts = needle.match(/^\/(.+)\/([gim]*)$/);
if (regParts) { if (regParts) {
// the parsed pattern is a regexp. // the parsed pattern is a regexp.
needle = new RegExp(regParts[1], regParts[2]); needle = new RegExp(regParts[1], regParts[2]);
} }
title = title.replace(needle, replacement); title = title.replace(needle, replacement);

View File

@ -81,8 +81,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
past = moment().startOf("day").subtract(maximumNumberOfDays, "days").toDate(); past = moment().startOf("day").subtract(maximumNumberOfDays, "days").toDate();
} }
// FIXME: // FIXME: Ugly fix to solve the facebook birthday issue.
// Ugly fix to solve the facebook birthday issue.
// Otherwise, the recurring events only show the birthday for next year. // Otherwise, the recurring events only show the birthday for next year.
var isFacebookBirthday = false; var isFacebookBirthday = false;
if (typeof event.uid !== "undefined") { if (typeof event.uid !== "undefined") {
@ -200,7 +199,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
// because the logic below will filter out any recurrences that don"t actually belong within // because the logic below will filter out any recurrences that don"t actually belong within
// our display range. // our display range.
// Would be great if there was a better way to handle this. // Would be great if there was a better way to handle this.
if (event.recurrences != undefined) if (event.recurrences !== undefined)
{ {
var pastMoment = moment(past); var pastMoment = moment(past);
var futureMoment = moment(future); var futureMoment = moment(future);
@ -209,7 +208,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
{ {
// Only add dates that weren't already in the range we added from the rrule so that // Only add dates that weren't already in the range we added from the rrule so that
// we don"t double-add those events. // we don"t double-add those events.
if (moment(new Date(r)).isBetween(pastMoment, futureMoment) != true) if (moment(new Date(r)).isBetween(pastMoment, futureMoment) !== true)
{ {
dates.push(new Date(r)); dates.push(new Date(r));
} }
@ -235,7 +234,7 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
startDate = moment(date); startDate = moment(date);
// For each date that we"re checking, it"s possible that there is a recurrence override for that one day. // For each date that we"re checking, it"s possible that there is a recurrence override for that one day.
if ((curEvent.recurrences != undefined) && (curEvent.recurrences[dateKey] != undefined)) if ((curEvent.recurrences !== undefined) && (curEvent.recurrences[dateKey] !== undefined))
{ {
// We found an override, so for this recurrence, use a potentially different title, start date, and duration. // We found an override, so for this recurrence, use a potentially different title, start date, and duration.
curEvent = curEvent.recurrences[dateKey]; curEvent = curEvent.recurrences[dateKey];
@ -243,14 +242,14 @@ var CalendarFetcher = function(url, reloadInterval, excludedEvents, maximumEntri
duration = parseInt(moment(curEvent.end).format("x")) - parseInt(startDate.format("x")); duration = parseInt(moment(curEvent.end).format("x")) - parseInt(startDate.format("x"));
} }
// If there"s no recurrence override, check for an exception date. Exception dates represent exceptions to the rule. // If there"s no recurrence override, check for an exception date. Exception dates represent exceptions to the rule.
else if ((curEvent.exdate != undefined) && (curEvent.exdate[dateKey] != undefined)) else if ((curEvent.exdate !== undefined) && (curEvent.exdate[dateKey] !== undefined))
{ {
// This date is an exception date, which means we should skip it in the recurrence pattern. // This date is an exception date, which means we should skip it in the recurrence pattern.
showRecurrence = false; showRecurrence = false;
} }
endDate = moment(parseInt(startDate.format("x")) + duration, "x"); endDate = moment(parseInt(startDate.format("x")) + duration, "x");
if (startDate.format("x") == endDate.format("x")) { if (startDate.format("x") === endDate.format("x")) {
endDate = endDate.endOf("day"); endDate = endDate.endOf("day");
} }

View File

@ -1,4 +1,5 @@
/* global Log, Module, moment, config */ /* global Log, Module, moment, config */
/* Magic Mirror /* Magic Mirror
* Module: Clock * Module: Clock
* *
@ -198,11 +199,10 @@ Module.register("clock",{
* Create wrappers for ANALOG clock, only if specified in config * Create wrappers for ANALOG clock, only if specified in config
*/ */
if (this.config.displayType !== "digital") { if (this.config.displayType !== "digital") {
// If it isn't 'digital', then an 'analog' clock was also requested // If it isn't 'digital', then an 'analog' clock was also requested
// Calculate the degree offset for each hand of the clock // Calculate the degree offset for each hand of the clock
var now = moment();
if (this.config.timezone) { if (this.config.timezone) {
now.tz(this.config.timezone); now.tz(this.config.timezone);
} }

View File

@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("currentweather",{ Module.register("currentweather",{
// Default module config. // Default module config.
@ -23,7 +22,6 @@ Module.register("currentweather",{
showWindDirection: true, showWindDirection: true,
showWindDirectionAsArrow: false, showWindDirectionAsArrow: false,
useBeaufort: true, useBeaufort: true,
appendLocationNameToHeader: false,
useKMPHwind: false, useKMPHwind: false,
lang: config.language, lang: config.language,
decimalSymbol: ".", decimalSymbol: ".",
@ -150,15 +148,15 @@ Module.register("currentweather",{
var humidity = document.createElement("span"); var humidity = document.createElement("span");
humidity.innerHTML = this.humidity; humidity.innerHTML = this.humidity;
var spacer = document.createElement("sup"); var supspacer = document.createElement("sup");
spacer.innerHTML = " "; supspacer.innerHTML = " ";
var humidityIcon = document.createElement("sup"); var humidityIcon = document.createElement("sup");
humidityIcon.className = "wi wi-humidity humidityIcon"; humidityIcon.className = "wi wi-humidity humidityIcon";
humidityIcon.innerHTML = " "; humidityIcon.innerHTML = " ";
small.appendChild(humidity); small.appendChild(humidity);
small.appendChild(spacer); small.appendChild(supspacer);
small.appendChild(humidityIcon); small.appendChild(humidityIcon);
} }
@ -414,8 +412,7 @@ Module.register("currentweather",{
case "imperial": tempInF = this.temperature; case "imperial": tempInF = this.temperature;
break; break;
case "default": case "default":
var tc = this.temperature - 273.15; tempInF = 1.8 * (this.temperature - 273.15) + 32;
tempInF = 1.8 * tc + 32;
break; break;
} }
@ -431,8 +428,7 @@ Module.register("currentweather",{
case "imperial": this.feelsLike = windChillInF.toFixed(0); case "imperial": this.feelsLike = windChillInF.toFixed(0);
break; break;
case "default": case "default":
var tc = windChillInC + 273.15; this.feelsLike = (windChillInC + 273.15).toFixed(0);
this.feelsLike = tc.toFixed(0);
break; break;
} }

View File

@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("helloworld",{ Module.register("helloworld",{
// Default module config. // Default module config.

View File

@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("newsfeed",{ Module.register("newsfeed",{
// Default module config. // Default module config.
@ -367,8 +366,8 @@ Module.register("newsfeed",{
}, },
notificationReceived: function(notification, payload, sender) { notificationReceived: function(notification, payload, sender) {
var before = this.activeItem;
if(notification === "ARTICLE_NEXT"){ if(notification === "ARTICLE_NEXT"){
var before = this.activeItem;
this.activeItem++; this.activeItem++;
if (this.activeItem >= this.newsItems.length) { if (this.activeItem >= this.newsItems.length) {
this.activeItem = 0; this.activeItem = 0;
@ -377,7 +376,6 @@ Module.register("newsfeed",{
Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")"); Log.info(this.name + " - going from article #" + before + " to #" + this.activeItem + " (of " + this.newsItems.length + ")");
this.updateDom(100); this.updateDom(100);
} else if(notification === "ARTICLE_PREVIOUS"){ } else if(notification === "ARTICLE_PREVIOUS"){
var before = this.activeItem;
this.activeItem--; this.activeItem--;
if (this.activeItem < 0) { if (this.activeItem < 0) {
this.activeItem = this.newsItems.length - 1; this.activeItem = this.newsItems.length - 1;

View File

@ -1,3 +1,11 @@
/* global Module */
/* Magic Mirror
* Module: UpdateNotification
*
* By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed.
*/
Module.register("updatenotification", { Module.register("updatenotification", {
defaults: { defaults: {
@ -33,16 +41,16 @@ Module.register("updatenotification", {
var self = this; var self = this;
if (payload && payload.behind > 0) { if (payload && payload.behind > 0) {
// if we haven't seen info for this module // if we haven't seen info for this module
if(this.moduleList[payload.module] == undefined){ if(this.moduleList[payload.module] === undefined){
// save it // save it
this.moduleList[payload.module]=payload; this.moduleList[payload.module]=payload;
self.updateDom(2); self.updateDom(2);
} }
//self.show(1000, { lockString: self.identifier }); //self.show(1000, { lockString: self.identifier });
} else if (payload && payload.behind == 0){ } else if (payload && payload.behind === 0){
// if the module WAS in the list, but shouldn't be // if the module WAS in the list, but shouldn't be
if(this.moduleList[payload.module] != undefined){ if(this.moduleList[payload.module] !== undefined){
// remove it // remove it
delete this.moduleList[payload.module]; delete this.moduleList[payload.module];
self.updateDom(2); self.updateDom(2);
@ -64,7 +72,7 @@ Module.register("updatenotification", {
// Override dom generator. // Override dom generator.
getDom: function () { getDom: function () {
var wrapper = document.createElement("div"); var wrapper = document.createElement("div");
if(this.suspended==false){ if(this.suspended === false){
// process the hash of module info found // process the hash of module info found
for(key of Object.keys(this.moduleList)){ for(key of Object.keys(this.moduleList)){
let m= this.moduleList[key]; let m= this.moduleList[key];
@ -77,7 +85,7 @@ Module.register("updatenotification", {
icon.innerHTML = "&nbsp;"; icon.innerHTML = "&nbsp;";
message.appendChild(icon); message.appendChild(icon);
var updateInfoKeyName = m.behind == 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE"; var updateInfoKeyName = m.behind === 1 ? "UPDATE_INFO_SINGLE" : "UPDATE_INFO_MULTIPLE";
var subtextHtml = this.translate(updateInfoKeyName, { var subtextHtml = this.translate(updateInfoKeyName, {
COMMIT_COUNT: m.behind, COMMIT_COUNT: m.behind,
@ -85,7 +93,7 @@ Module.register("updatenotification", {
}); });
var text = document.createElement("span"); var text = document.createElement("span");
if (m.module == "default") { if (m.module === "default") {
text.innerHTML = this.translate("UPDATE_NOTIFICATION"); text.innerHTML = this.translate("UPDATE_NOTIFICATION");
subtextHtml = this.diffLink(m,subtextHtml); subtextHtml = this.diffLink(m,subtextHtml);
} else { } else {

View File

@ -1,5 +1,5 @@
# Weather Module # Weather Module
This module is aimed to be the replacement for the current `currentweather` and `weatherforcast` modules. The module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fullfil both purposes. This module aims to be the replacement for the current `currentweather` and `weatherforcast` modules. The module will be configurable to be used as a current weather view, or to show the forecast. This way the module can be used twice to fullfil both purposes.
For configuration options, please check the [MagicMirror² documentation](https://docs.magicmirror.builders/modules/weather.html). For configuration options, please check the [MagicMirror² documentation](https://docs.magicmirror.builders/modules/weather.html).

View File

@ -13,7 +13,7 @@ Table of Contents:
## The weather provider file: yourprovider.js ## The weather provider file: yourprovider.js
This is the script in which the weather provider will be defined. In it's most simple form, the weather provider must implement the following: This is the script in which the weather provider will be defined. In its most simple form, the weather provider must implement the following:
````javascript ````javascript
WeatherProvider.register("yourprovider", { WeatherProvider.register("yourprovider", {
@ -36,7 +36,7 @@ It will then automatically refresh the module DOM with the new data.
#### `fetchWeatherForecast()` #### `fetchWeatherForecast()`
This method is called when the weather module tries to fetch the weather weather of your provider. The implementation of this method is required. This method is called when the weather module tries to fetch the weather of your provider. The implementation of this method is required.
The implementation can make use of the already implemented function `this.fetchData(url, method, data);`, which is returning a promise. The implementation can make use of the already implemented function `this.fetchData(url, method, data);`, which is returning a promise.
After the response is processed, the weather forecast information (as an array of [WeatherObject](#weatherobject)s) needs to be set with `this.setCurrentWeather(forecast);`. After the response is processed, the weather forecast information (as an array of [WeatherObject](#weatherobject)s) needs to be set with `this.setCurrentWeather(forecast);`.
It will then automatically refresh the module DOM with the new data. It will then automatically refresh the module DOM with the new data.

View File

@ -1,4 +1,4 @@
/* global WeatherProvider, WeatherDay */ /* global WeatherProvider */
/* Magic Mirror /* Magic Mirror
* Module: Weather * Module: Weather

View File

@ -8,7 +8,6 @@
* *
* This class is the blueprint for a weather provider. * This class is the blueprint for a weather provider.
*/ */
WeatherProvider.register("openweathermap", { WeatherProvider.register("openweathermap", {
// Set the name of the provider. // Set the name of the provider.

View File

@ -8,7 +8,6 @@
* *
* This class is a provider for UK Met Office Datapoint. * This class is a provider for UK Met Office Datapoint.
*/ */
WeatherProvider.register("ukmetoffice", { WeatherProvider.register("ukmetoffice", {
// Set the name of the provider. // Set the name of the provider.
@ -25,8 +24,7 @@ WeatherProvider.register("ukmetoffice", {
fetchCurrentWeather() { fetchCurrentWeather() {
this.fetchData(this.getUrl("3hourly")) this.fetchData(this.getUrl("3hourly"))
.then(data => { .then(data => {
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
!data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length == 0) {
// Did not receive usable new data. // Did not receive usable new data.
// Maybe this needs a better check? // Maybe this needs a better check?
return; return;
@ -47,8 +45,7 @@ WeatherProvider.register("ukmetoffice", {
fetchWeatherForecast() { fetchWeatherForecast() {
this.fetchData(this.getUrl("daily")) this.fetchData(this.getUrl("daily"))
.then(data => { .then(data => {
if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || if (!data || !data.SiteRep || !data.SiteRep.DV || !data.SiteRep.DV.Location || !data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length === 0) {
!data.SiteRep.DV.Location.Period || data.SiteRep.DV.Location.Period.length == 0) {
// Did not receive usable new data. // Did not receive usable new data.
// Maybe this needs a better check? // Maybe this needs a better check?
return; return;

View File

@ -11,7 +11,6 @@
* Note that this is only for US locations (lat and lon) and does not require an API key * Note that this is only for US locations (lat and lon) and does not require an API key
* Since it is free, there are some items missing - like sunrise, sunset, humidity, etc. * Since it is free, there are some items missing - like sunrise, sunset, humidity, etc.
*/ */
WeatherProvider.register("weathergov", { WeatherProvider.register("weathergov", {
// Set the name of the provider. // Set the name of the provider.

View File

@ -6,11 +6,9 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("weather",{ Module.register("weather",{
// Default module config. // Default module config.
defaults: { defaults: {
updateInterval: 10 * 60 * 1000,
weatherProvider: "openweathermap", weatherProvider: "openweathermap",
roundTemp: false, roundTemp: false,
type: "current", //current, forecast type: "current", //current, forecast
@ -210,11 +208,11 @@ Module.register("weather",{
if (isNaN(value) || value === 0 || value.toFixed(2) === "0.00") { if (isNaN(value) || value === 0 || value.toFixed(2) === "0.00") {
value = ""; value = "";
} else { } else {
if (this.config.weatherProvider === "ukmetoffice") { if (this.config.weatherProvider === "ukmetoffice") {
value += "%"; value += "%";
} else { } else {
value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`; value = `${value.toFixed(2)} ${this.config.units === "imperial" ? "in" : "mm"}`;
} }
} }
} else if (type === "humidity") { } else if (type === "humidity") {
value += "%"; value += "%";

View File

@ -1,5 +1,3 @@
/* global Class */
/* Magic Mirror /* Magic Mirror
* Module: Weather * Module: Weather
* *
@ -7,11 +5,10 @@
* MIT Licensed. * MIT Licensed.
* *
* This class is the blueprint for a day which includes weather information. * This class is the blueprint for a day which includes weather information.
*
* Currently this is focused on the information which is necessary for the current weather.
* As soon as we start implementing the forecast, mode properties will be added.
*/ */
// Currently this is focused on the information which is necessary for the current weather.
// As soon as we start implementing the forecast, mode properties will be added.
class WeatherObject { class WeatherObject {
constructor(units, tempUnits, windUnits) { constructor(units, tempUnits, windUnits) {
@ -87,8 +84,8 @@ class WeatherObject {
} }
feelsLike() { feelsLike() {
if (this.feelsLikeTemp) { if (this.feelsLikeTemp) {
return this.feelsLikeTemp; return this.feelsLikeTemp;
} }
const windInMph = (this.windUnits === "imperial") ? this.windSpeed : this.windSpeed * 2.23694; const windInMph = (this.windUnits === "imperial") ? this.windSpeed : this.windSpeed * 2.23694;
const tempInF = this.tempUnits === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32; const tempInF = this.tempUnits === "imperial" ? this.temperature : this.temperature * 9 / 5 + 32;

View File

@ -8,10 +8,6 @@
* *
* This class is the blueprint for a weather provider. * This class is the blueprint for a weather provider.
*/ */
/**
* Base BluePrint for the WeatherProvider
*/
var WeatherProvider = Class.extend({ var WeatherProvider = Class.extend({
// Weather Provider Properties // Weather Provider Properties
providerName: null, providerName: null,

View File

@ -6,7 +6,6 @@
* By Michael Teeuw http://michaelteeuw.nl * By Michael Teeuw http://michaelteeuw.nl
* MIT Licensed. * MIT Licensed.
*/ */
Module.register("weatherforecast",{ Module.register("weatherforecast",{
// Default module config. // Default module config.
@ -62,7 +61,7 @@ Module.register("weatherforecast",{
}, },
}, },
// create a variable for the first upcoming calendaar event. Used if no location is specified. // create a variable for the first upcoming calendar event. Used if no location is specified.
firstEvent: false, firstEvent: false,
// create a variable to hold the location name based on the API result. // create a variable to hold the location name based on the API result.
@ -310,7 +309,7 @@ Module.register("weatherforecast",{
* parserDataWeather(data) * parserDataWeather(data)
* *
* Use the parse to keep the same struct between daily and forecast Endpoint * Use the parse to keep the same struct between daily and forecast Endpoint
* from Openweather * from openweather.org
* *
*/ */
parserDataWeather: function(data) { parserDataWeather: function(data) {
@ -339,7 +338,7 @@ Module.register("weatherforecast",{
var day; var day;
var hour; var hour;
if(!!forecast.dt_txt) { if(forecast.dt_txt) {
day = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").format("ddd"); day = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").format("ddd");
hour = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").format("H"); hour = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").format("H");
} else { } else {
@ -348,7 +347,7 @@ Module.register("weatherforecast",{
} }
if (day !== lastDay) { if (day !== lastDay) {
var forecastData = { forecastData = {
day: day, day: day,
icon: this.config.iconTable[forecast.weather[0].icon], icon: this.config.iconTable[forecast.weather[0].icon],
maxTemp: this.roundValue(forecast.temp.max), maxTemp: this.roundValue(forecast.temp.max),
@ -450,14 +449,14 @@ Module.register("weatherforecast",{
} }
//Find all forecasts that is for the same day //Find all forecasts that is for the same day
var checkDateTime = (!!forecast.dt_txt) ? moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(forecast.dt, "X"); var checkDateTime = (forecast.dt_txt) ? moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(forecast.dt, "X");
var daysForecasts = allForecasts.filter(function(item) { var daysForecasts = allForecasts.filter(function(item) {
var itemDateTime = (!!item.dt_txt) ? moment(item.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(item.dt, "X"); var itemDateTime = (item.dt_txt) ? moment(item.dt_txt, "YYYY-MM-DD hh:mm:ss") : moment(item.dt, "X");
return itemDateTime.isSame(checkDateTime, "day") && item.rain instanceof Object; return itemDateTime.isSame(checkDateTime, "day") && item.rain instanceof Object;
}); });
//If no rain this day return undefined so it wont be displayed for this day //If no rain this day return undefined so it wont be displayed for this day
if (daysForecasts.length == 0) { if (daysForecasts.length === 0) {
return undefined; return undefined;
} }

477
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -44,20 +44,19 @@
"homepage": "https://magicmirror.builders", "homepage": "https://magicmirror.builders",
"devDependencies": { "devDependencies": {
"@prantlf/jsonlint": "^10.2.0", "@prantlf/jsonlint": "^10.2.0",
"chai": "^4.1.2", "chai": "^4.2.0",
"chai-as-promised": "^7.1.1", "chai-as-promised": "^7.1.1",
"current-week-number": "^1.0.7", "current-week-number": "^1.0.7",
"danger": "^3.1.3", "danger": "^3.1.3",
"eslint": "^6.8.0",
"http-auth": "^3.2.3", "http-auth": "^3.2.3",
"jsdom": "^11.6.2", "jsdom": "^11.6.2",
"markdownlint": "^0.20.1", "markdownlint": "^0.20.1",
"markdownlint-cli": "^0.22.0", "markdownlint-cli": "^0.22.0",
"mocha": "^7.0.0", "mocha": "^7.1.1",
"mocha-each": "^1.1.0", "mocha-each": "^2.0.1",
"mocha-logger": "^1.0.6", "mocha-logger": "^1.0.6",
"spectron": "^8.0.0", "spectron": "^8.0.0",
"stylelint": "^13.3.2", "stylelint": "^13.3.3",
"stylelint-config-standard": "^20.0.0", "stylelint-config-standard": "^20.0.0",
"yaml-lint": "^1.2.4" "yaml-lint": "^1.2.4"
}, },
@ -67,6 +66,7 @@
"dependencies": { "dependencies": {
"colors": "^1.1.2", "colors": "^1.1.2",
"console-stamp": "^0.2.9", "console-stamp": "^0.2.9",
"eslint": "^6.8.0",
"express": "^4.16.2", "express": "^4.16.2",
"express-ipfilter": "^1.0.1", "express-ipfilter": "^1.0.1",
"feedme": "latest", "feedme": "latest",

View File

@ -1,5 +1,5 @@
/* Magic Mirror Test config default calendar /* Magic Mirror Test config default calendar
* with authenticacion old config * with authentication old config
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed. * MIT Licensed.
*/ */

View File

@ -1,7 +1,4 @@
/* Magic Mirror Test config for default clock module
/* Magic Mirror
*
* Test config for default clock module
* Language es for showWeek feature * Language es for showWeek feature
* *
* By Rodrigo Ramírez Norambuena * By Rodrigo Ramírez Norambuena

View File

@ -1,6 +1,4 @@
/* Magic Mirror /* Magic Mirror Test config sample module hello world default config
*
* Test config sample module hello world default config
* *
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed. * MIT Licensed.

View File

@ -9,7 +9,6 @@
var config = { var config = {
port: 8080, port: 8080,
ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"],
ipWhitelist: [],
language: "en", language: "en",
timeFormat: 24, timeFormat: 24,
@ -19,6 +18,7 @@ var config = {
nodeIntegration: true, nodeIntegration: true,
}, },
}, },
modules: modules:
// Using exotic content. This is why dont accept go to JSON configuration file // Using exotic content. This is why dont accept go to JSON configuration file
(function() { (function() {

View File

@ -5,11 +5,11 @@ const describe = global.describe;
const it = global.it; const it = global.it;
describe("Development console tests", function() { describe("Development console tests", function() {
// This tests fail and crash another tests // FIXME: This tests fail and crash another tests
// Suspect problem with window focus // Suspect problem with window focus
// FIXME
return false; return false;
/* eslint-disable */
helpers.setupTimeout(this); helpers.setupTimeout(this);
var app = null; var app = null;
@ -58,4 +58,5 @@ describe("Development console tests", function() {
return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true); return expect(app.browserWindow.isDevToolsOpened()).to.eventually.equal(true);
}); });
}); });
/* eslint-enable */
}); });