diff --git a/modules/default/weather/current.njk b/modules/default/weather/current.njk index 51687231eb..08ff49c277 100644 --- a/modules/default/weather/current.njk +++ b/modules/default/weather/current.njk @@ -90,6 +90,8 @@ {% if config.showHumidity === "below" %} {{ humidity() }} {% endif %} + {% elseif error %} +
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}
{% else %}
{{ "LOADING" | translate }}
{% endif %} diff --git a/modules/default/weather/forecast.njk b/modules/default/weather/forecast.njk index 50c6bb53d8..d82bc8a7ac 100644 --- a/modules/default/weather/forecast.njk +++ b/modules/default/weather/forecast.njk @@ -39,6 +39,8 @@ {% set currentStep = currentStep + 1 %} {% endfor %} + {% elseif error %} +
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}
{% else %}
{{ "LOADING" | translate }}
{% endif %} diff --git a/modules/default/weather/hourly.njk b/modules/default/weather/hourly.njk index 05416de7dd..2b98d821a5 100644 --- a/modules/default/weather/hourly.njk +++ b/modules/default/weather/hourly.njk @@ -41,6 +41,8 @@ {% set currentStep = currentStep + 1 %} {% endfor %} + {% elseif error %} +
{{ "MODULE_CONFIG_ERROR" | translate({MODULE_NAME: "Weather", ERROR: error}) | safe }}
{% else %}
{{ "LOADING" | translate }}
{% endif %} diff --git a/modules/default/weather/providers/openmeteo.js b/modules/default/weather/providers/openmeteo.js index d80b670162..9a3c9033aa 100644 --- a/modules/default/weather/providers/openmeteo.js +++ b/modules/default/weather/providers/openmeteo.js @@ -143,56 +143,41 @@ WeatherProvider.register("openmeteo", { }, fetchCurrentWeather () { - this.fetchData(this.getUrl()) + return this.fetchData(this.getUrl()) .then((data) => this.parseWeatherApiResponse(data)) .then((parsedData) => { if (!parsedData) { - // No usable data? - return; + throw new Error("No usable data ..."); } - const currentWeather = this.generateWeatherDayFromCurrentWeather(parsedData); this.setCurrentWeather(currentWeather); }) - .catch(function (request) { - Log.error("[weatherprovider.openmeteo] Could not load data ... ", request); - }) .finally(() => this.updateAvailable()); }, fetchWeatherForecast () { - this.fetchData(this.getUrl()) + return this.fetchData(this.getUrl()) .then((data) => this.parseWeatherApiResponse(data)) .then((parsedData) => { if (!parsedData) { - // No usable data? - return; + throw new Error("No usable data ..."); } - const dailyForecast = this.generateWeatherObjectsFromForecast(parsedData); this.setWeatherForecast(dailyForecast); }) - .catch(function (request) { - Log.error("[weatherprovider.openmeteo] Could not load data ... ", request); - }) .finally(() => this.updateAvailable()); }, fetchWeatherHourly () { - this.fetchData(this.getUrl()) + return this.fetchData(this.getUrl()) .then((data) => this.parseWeatherApiResponse(data)) .then((parsedData) => { if (!parsedData) { - // No usable data? - return; + throw new Error("No usable data ..."); } - const hourlyForecast = this.generateWeatherObjectsFromHourly(parsedData); this.setWeatherHourly(hourlyForecast); }) - .catch(function (request) { - Log.error("[weatherprovider.openmeteo] Could not load data ... ", request); - }) .finally(() => this.updateAvailable()); }, diff --git a/modules/default/weather/providers/ukmetofficedatahub.js b/modules/default/weather/providers/ukmetofficedatahub.js index d3e3d6195c..3ea0888b99 100644 --- a/modules/default/weather/providers/ukmetofficedatahub.js +++ b/modules/default/weather/providers/ukmetofficedatahub.js @@ -271,6 +271,7 @@ WeatherProvider.register("ukmetofficedatahub", { 30: "thunderstorm" }; + // TODO check for duplicat eand if neeeded return weatherTypes.hasOwnProperty(weatherType) ? weatherTypes[weatherType] : null; } }); diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 4b33682c21..404bae2eaa 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -48,6 +48,8 @@ Module.register("weather", { // Module properties. weatherProvider: null, + error: null, + // Can be used by the provider to display location of event if nothing else is specified firstEvent: null, @@ -149,6 +151,12 @@ Module.register("weather", { // Skip some hourly forecast entries if configured const hourlyData = this.weatherProvider.weatherHourly()?.filter((e, i) => (i + 1) % this.config.hourlyForecastIncrements === this.config.hourlyForecastIncrements - 1); + if (this.error) { + return { + error: this.error + }; + } + return { config: this.config, current: currentData, @@ -195,20 +203,26 @@ Module.register("weather", { nextLoad = delay; } - setTimeout(() => { - switch (this.config.type.toLowerCase()) { - case "current": - this.weatherProvider.fetchCurrentWeather(); - break; - case "hourly": - this.weatherProvider.fetchWeatherHourly(); - break; - case "daily": - case "forecast": - this.weatherProvider.fetchWeatherForecast(); - break; - default: - Log.error(`[weather] Invalid type ${this.config.type} configured (must be one of 'current', 'hourly', 'daily' or 'forecast')`); + setTimeout(async () => { + try { + switch (this.config.type.toLowerCase()) { + case "current": + await this.weatherProvider.fetchCurrentWeather(); + break; + case "hourly": + this.weatherProvider.fetchWeatherHourly(); + break; + case "daily": + case "forecast": + this.weatherProvider.fetchWeatherForecast(); + break; + default: + Log.error(`[weather] Invalid type ${this.config.type} configured (must be one of 'current', 'hourly', 'daily' or 'forecast')`); + } + this.error = null; + } catch (error) { + this.error = error; + this.updateAvailable(); } }, nextLoad); }, diff --git a/modules/default/weather/weatherprovider.js b/modules/default/weather/weatherprovider.js index 1c562f1541..f0f207db37 100644 --- a/modules/default/weather/weatherprovider.js +++ b/modules/default/weather/weatherprovider.js @@ -41,19 +41,19 @@ const WeatherProvider = Class.extend({ // This method should start the API request to fetch the current weather. // This method should definitely be overwritten in the provider. - fetchCurrentWeather () { + async fetchCurrentWeather () { Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchCurrentWeather method.`); }, // This method should start the API request to fetch the weather forecast. // This method should definitely be overwritten in the provider. - fetchWeatherForecast () { + async fetchWeatherForecast () { Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchWeatherForecast method.`); }, // This method should start the API request to fetch the weather hourly. // This method should definitely be overwritten in the provider. - fetchWeatherHourly () { + async fetchWeatherHourly () { Log.warn(`[weatherprovider] ${this.providerName} does not subclass the fetchWeatherHourly method.`); }, diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 56d2a45ad5..95357a111e 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -9,7 +9,7 @@ describe("Calendar module", () => { * @param {string} not reverse result * @returns {boolean} result */ - const testElementLength = async (element, result, not) => { + const testElementLength = async (element, result, not = "") => { const elem = await helpers.waitForAllElements(element); expect(elem).not.toBeNull(); if (not === "not") {