Skip to content

Commit 7fdf7de

Browse files
authored
Merge pull request #2600 from njwilliams/njw/openweathermap-onecall-fix
2 parents b75eedb + 775d109 commit 7fdf7de

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Special thanks to the following contributors: @B1gG, @codac, @ezeholz, @khassel,
4848
- Fix calendar start function logging inconsistency.
4949
- Fix updatenotification start function logging inconsistency.
5050
- Checks and applies the showDescription setting for the newsfeed module again
51+
- Fix issue with openweathermap not showing current or forecast info when using onecall API
5152
- Fix tests in weather module and add one for decimalPoint in forecast
5253
- Fix decimalSymbol in the forecast part of the new weather module #2530
5354
- Fix wrong treatment of `appendLocationNameToHeader` when using `ukmetofficedatahub`

modules/default/weather/providers/openweathermap.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,14 @@ WeatherProvider.register("openweathermap", {
3030
fetchCurrentWeather() {
3131
this.fetchData(this.getUrl())
3232
.then((data) => {
33-
if (!data || !data.main || typeof data.main.temp === "undefined") {
34-
// Did not receive usable new data.
35-
// Maybe this needs a better check?
36-
return;
33+
if (this.config.weatherEndpoint === "/onecall") {
34+
const weatherData = this.generateWeatherObjectsFromOnecall(data);
35+
this.setCurrentWeather(weatherData.current);
36+
this.setFetchedLocation(`${data.timezone}`);
37+
} else {
38+
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
39+
this.setCurrentWeather(currentWeather);
3740
}
38-
39-
this.setFetchedLocation(`${data.name}, ${data.sys.country}`);
40-
41-
const currentWeather = this.generateWeatherObjectFromCurrentWeather(data);
42-
this.setCurrentWeather(currentWeather);
4341
})
4442
.catch(function (request) {
4543
Log.error("Could not load data ... ", request);
@@ -51,16 +49,15 @@ WeatherProvider.register("openweathermap", {
5149
fetchWeatherForecast() {
5250
this.fetchData(this.getUrl())
5351
.then((data) => {
54-
if (!data || !data.list || !data.list.length) {
55-
// Did not receive usable new data.
56-
// Maybe this needs a better check?
57-
return;
52+
if (this.config.weatherEndpoint === "/onecall") {
53+
const weatherData = this.generateWeatherObjectsFromOnecall(data);
54+
this.setWeatherForecast(weatherData.days);
55+
this.setFetchedLocation(`${data.timezone}`);
56+
} else {
57+
const forecast = this.generateWeatherObjectsFromForecast(data.list);
58+
this.setWeatherForecast(forecast);
59+
this.setFetchedLocation(`${data.city.name}, ${data.city.country}`);
5860
}
59-
60-
this.setFetchedLocation(`${data.city.name}, ${data.city.country}`);
61-
62-
const forecast = this.generateWeatherObjectsFromForecast(data.list);
63-
this.setWeatherForecast(forecast);
6461
})
6562
.catch(function (request) {
6663
Log.error("Could not load data ... ", request);

0 commit comments

Comments
 (0)