mirror of
https://github.com/MichMich/MagicMirror.git
synced 2026-07-27 23:59:50 -07:00
fix(weather): use nearest openmeteo hourly data (#4123)
Open-Meteo updates `current_weather` every 15 minutes, but the hourly array only has entries at full hours. The old code did an exact timestamp match - so at 14:15, 14:30 or 14:45 it never found a match and silently fell back to index 0, showing midnight values for humidity, feels-like temp, precipitation, etc. Fix: `findLastIndex((hour) => hour.time <= currentMs)` - the last hourly entry at or before the current time. While fixing the bug I found several dead branches left over from the #4032 refactor: a path for pre-transposed hourly data that `#parseWeatherApiResponse` makes unreachable, an `Array.isArray` guard that's always true, and a `Log.debug` inside the dead branch. Removing those accounts for most of the ~40 deleted lines - the actual fix is one line. Fixes #4122.
This commit is contained in:
@@ -144,12 +144,15 @@ describe("OpenMeteoProvider", () => {
|
||||
provider.start();
|
||||
|
||||
const result = await dataPromise;
|
||||
const currentHourUnix = Math.floor(currentData.current_weather.time / 3600) * 3600;
|
||||
const currentHourIndex = currentData.hourly.time.findIndex((time) => time === currentHourUnix);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result.temperature).toBe(8.5);
|
||||
expect(result.windSpeed).toBeCloseTo(4.7, 1);
|
||||
expect(result.windFromDirection).toBe(9);
|
||||
expect(result.humidity).toBe(83);
|
||||
expect(result.humidity).toBe(currentData.hourly.relativehumidity_2m[currentHourIndex]);
|
||||
expect(result.humidity).not.toBe(currentData.hourly.relativehumidity_2m[0]);
|
||||
});
|
||||
|
||||
it("should include sunrise and sunset from daily data", async () => {
|
||||
|
||||
Reference in New Issue
Block a user