diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index 2fde7139..ba8a22a3 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -77,6 +77,18 @@ WeatherProvider.register("openweathermap", { .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 */ /* * Gets the complete url for the request diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index defe0ae5..b2214105 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -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); },