Moving openweathermap specific check for hourly into its provider and make invalid types fail nicer

This commit is contained in:
buxxi
2021-01-23 10:13:41 +01:00
parent a3cb0b7b96
commit d48113f2d9
2 changed files with 27 additions and 8 deletions

View File

@@ -129,9 +129,9 @@ Module.register("weather", {
return `hourly.njk`;
case "daily":
case "forecast":
return `forecast.njk`;
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(() => {
if (this.config.weatherEndpoint === "/onecall") {
this.weatherProvider.fetchWeatherData();
} else if (this.config.type === "forecast") {
this.weatherProvider.fetchWeatherForecast();
} else {
this.weatherProvider.fetchCurrentWeather();
switch (this.config.type.toLowerCase()) {
case "current":
this.weatherProvider.fetchCurrentWeather();
break;
case "hourly":
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);
},