mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-28 04:02:12 +00:00
Moving openweathermap specific check for hourly into its provider and make invalid types fail nicer
This commit is contained in:
parent
a3cb0b7b96
commit
d48113f2d9
@ -77,6 +77,18 @@ WeatherProvider.register("openweathermap", {
|
|||||||
.finally(() => this.updateAvailable());
|
.finally(() => this.updateAvailable());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides method for setting config to check if endpoint is correct for hourly
|
||||||
|
*
|
||||||
|
* @param config
|
||||||
|
*/
|
||||||
|
setConfig(config) {
|
||||||
|
this.config = config;
|
||||||
|
if (this.config.type === "hourly") {
|
||||||
|
this.config.weatherEndpoint = "/onecall";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */
|
/** OpenWeatherMap Specific Methods - These are not part of the default provider methods */
|
||||||
/*
|
/*
|
||||||
* Gets the complete url for the request
|
* Gets the complete url for the request
|
||||||
|
@ -129,9 +129,9 @@ Module.register("weather", {
|
|||||||
return `hourly.njk`;
|
return `hourly.njk`;
|
||||||
case "daily":
|
case "daily":
|
||||||
case "forecast":
|
case "forecast":
|
||||||
return `forecast.njk`;
|
|
||||||
default:
|
default:
|
||||||
return `${this.config.type.toLowerCase()}.njk`;
|
//Make the invalid values use the "Loading..." from forecast
|
||||||
|
return `forecast.njk`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -167,12 +167,19 @@ Module.register("weather", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (this.config.weatherEndpoint === "/onecall") {
|
switch (this.config.type.toLowerCase()) {
|
||||||
this.weatherProvider.fetchWeatherData();
|
case "current":
|
||||||
} else if (this.config.type === "forecast") {
|
this.weatherProvider.fetchCurrentWeather();
|
||||||
this.weatherProvider.fetchWeatherForecast();
|
break;
|
||||||
} else {
|
case "hourly":
|
||||||
this.weatherProvider.fetchCurrentWeather();
|
this.weatherProvider.fetchWeatherData();
|
||||||
|
break;
|
||||||
|
case "daily":
|
||||||
|
case "forecast":
|
||||||
|
this.weatherProvider.fetchWeatherForecast();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Log.error(`Invalid type ${this.config.type} configured (must be one of 'current', 'hourly', 'daily' or 'forecast')`);
|
||||||
}
|
}
|
||||||
}, nextLoad);
|
}, nextLoad);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user