From e6866118905d88cd1ea729bc0274b100ee773c3e Mon Sep 17 00:00:00 2001 From: Nick Williams Date: Mon, 14 Jun 2021 21:55:19 -0400 Subject: [PATCH 1/2] update One Call API results for openweathermap The results from the /onecall endpoint were not being parsed correctly in current and forecast mode - it was assuming the current/forecast endpoint API, and the return datasets are different. The effect was that the module would simply display "Loading..." when in /onecall mode, since it has no way of displaying error status (ideally, it should, but leave that for another day) --- CHANGELOG.md | 1 + .../weather/providers/openweathermap.js | 33 +++++++++---------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b5a9d037..f82faa04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -41,6 +41,7 @@ Special thanks to the following contributors: @B1gG, @codac, @ezeholz, @khassel, - Fix calendar start function logging inconsistency. - Fix updatenotification start function logging inconsistency. - Checks and applies the showDescription setting for the newsfeed module again +- Fix issue with openweathermap not showing current or forecast info when using onecall API - Fix tests in weather module and add one for decimalPoint in forecast - Fix decimalSymbol in the forecast part of the new weather module #2530 - Fix wrong treatment of `appendLocationNameToHeader` when using `ukmetofficedatahub` diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index 2d0645fc..62441654 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -30,16 +30,14 @@ WeatherProvider.register("openweathermap", { fetchCurrentWeather() { this.fetchData(this.getUrl()) .then((data) => { - if (!data || !data.main || typeof data.main.temp === "undefined") { - // Did not receive usable new data. - // Maybe this needs a better check? - return; + if (this.config.weatherEndpoint === "/onecall") { + const weatherData = this.generateWeatherObjectsFromOnecall(data); + this.setCurrentWeather(weatherData.current); + this.setFetchedLocation(`${data.timezone}`); + } else { + const currentWeather = this.generateWeatherObjectFromCurrentWeather(data); + this.setCurrentWeather(currentWeather); } - - this.setFetchedLocation(`${data.name}, ${data.sys.country}`); - - const currentWeather = this.generateWeatherObjectFromCurrentWeather(data); - this.setCurrentWeather(currentWeather); }) .catch(function (request) { Log.error("Could not load data ... ", request); @@ -51,16 +49,15 @@ WeatherProvider.register("openweathermap", { fetchWeatherForecast() { this.fetchData(this.getUrl()) .then((data) => { - if (!data || !data.list || !data.list.length) { - // Did not receive usable new data. - // Maybe this needs a better check? - return; + if (this.config.weatherEndpoint === "/onecall") { + const weatherData = this.generateWeatherObjectsFromOnecall(data); + this.setWeatherForecast(weatherData.days); + this.setFetchedLocation(`${data.timezone}`); + } else { + const forecast = this.generateWeatherObjectsFromForecast(data.daily); + this.setWeatherForecast(forecast); + this.setFetchedLocation(`${data.city.name}, ${data.city.country}`); } - - this.setFetchedLocation(`${data.city.name}, ${data.city.country}`); - - const forecast = this.generateWeatherObjectsFromForecast(data.list); - this.setWeatherForecast(forecast); }) .catch(function (request) { Log.error("Could not load data ... ", request); From 775d1091db9bc243228391ecfb6f4b8c4b45f18e Mon Sep 17 00:00:00 2001 From: Nick Williams Date: Thu, 24 Jun 2021 21:39:32 -0400 Subject: [PATCH 2/2] typo when not using /onecall - was getting forecast from wrong attr --- modules/default/weather/providers/openweathermap.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/default/weather/providers/openweathermap.js b/modules/default/weather/providers/openweathermap.js index 62441654..bbe74d3b 100755 --- a/modules/default/weather/providers/openweathermap.js +++ b/modules/default/weather/providers/openweathermap.js @@ -54,7 +54,7 @@ WeatherProvider.register("openweathermap", { this.setWeatherForecast(weatherData.days); this.setFetchedLocation(`${data.timezone}`); } else { - const forecast = this.generateWeatherObjectsFromForecast(data.daily); + const forecast = this.generateWeatherObjectsFromForecast(data.list); this.setWeatherForecast(forecast); this.setFetchedLocation(`${data.city.name}, ${data.city.country}`); }