Skip to content

Commit d6f2e71

Browse files
authored
Fix frozen Yr weather-module (#3706)
Fixes #3296 The problem was that the fetch-methods threw errors when something went wrong instead of calling `updateAvailable()`. `updateAvailable()` must be called in order to schedule the next update. I added some filtering for the hourly forecast that removes hours in the past. If the API call fails we use the cached data, but we should only display hours in the future.
1 parent af77b7b commit d6f2e71

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ planned for 2025-04-01
2121
- [core] Optimize systeminformation calls and output (#3689)
2222
- [core] Add issue templates for feature requests and bug reports (#3695)
2323
- [core] Adapt `start:x11:dev` script
24+
- [weather/yr] The Yr weather provider now enforces a minimum `updateInterval` of 600 000 ms (10 minutes) to comply with the terms of service. If a lower value is set, it will be automatically increased to this minimum.
2425

2526
### Removed
2627

@@ -36,6 +37,7 @@ planned for 2025-04-01
3637
- [weather] Fix wrong weatherCondition name in openmeteo provider which lead to n/a icon (#3691)
3738
- [core] Fix wrong port in log message when starting server only (#3696)
3839
- [calendar] NewYork event processed on system in Central timezone shows wrong time #3701
40+
- [weather/yr] The Yr weather provider is now able to recover from bad API resposes instead of freezing (#3296)
3941

4042
## [2.30.0] - 2025-01-01
4143

modules/default/weather/providers/yr.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ WeatherProvider.register("yr", {
2323
Log.error("The Yr weather provider requires local storage.");
2424
throw new Error("Local storage not available");
2525
}
26+
if (this.config.updateInterval < 600000) {
27+
Log.warn("The Yr weather provider requires a minimum update interval of 10 minutes (600 000 ms). The configuration has been adjusted to meet this requirement.");
28+
this.delegate.config.updateInterval = 600000;
29+
}
2630
Log.info(`Weather provider: ${this.providerName} started.`);
2731
},
2832

@@ -34,7 +38,7 @@ WeatherProvider.register("yr", {
3438
})
3539
.catch((error) => {
3640
Log.error(error);
37-
throw new Error(error);
41+
this.updateAvailable();
3842
});
3943
},
4044

@@ -119,7 +123,12 @@ WeatherProvider.register("yr", {
119123
})
120124
.catch((err) => {
121125
Log.error(err);
122-
reject("Unable to get weather data from Yr.");
126+
if (weatherData) {
127+
Log.warn("Using outdated cached weather data.");
128+
resolve(weatherData);
129+
} else {
130+
reject("Unable to get weather data from Yr.");
131+
}
123132
})
124133
.finally(() => {
125134
localStorage.removeItem("yrIsFetchingWeatherData");
@@ -497,7 +506,7 @@ WeatherProvider.register("yr", {
497506
})
498507
.catch((error) => {
499508
Log.error(error);
500-
throw new Error(error);
509+
this.updateAvailable();
501510
});
502511
},
503512

@@ -530,7 +539,15 @@ WeatherProvider.register("yr", {
530539
getHourlyForecastFrom (weatherData) {
531540
const series = [];
532541

542+
const now = moment({
543+
year: moment().year(),
544+
month: moment().month(),
545+
day: moment().date(),
546+
hour: moment().hour()
547+
});
533548
for (const forecast of weatherData.properties.timeseries) {
549+
if (now.isAfter(moment(forecast.time))) continue;
550+
534551
forecast.symbol = forecast.data.next_1_hours?.summary?.symbol_code;
535552
forecast.precipitationAmount = forecast.data.next_1_hours?.details?.precipitation_amount;
536553
forecast.precipitationProbability = forecast.data.next_1_hours?.details?.probability_of_precipitation;
@@ -600,7 +617,7 @@ WeatherProvider.register("yr", {
600617
})
601618
.catch((error) => {
602619
Log.error(error);
603-
throw new Error(error);
620+
this.updateAvailable();
604621
});
605622
}
606623
});

0 commit comments

Comments
 (0)