fix: preserve partial IMGW Hybrid coverage

This commit is contained in:
zv
2026-06-02 18:06:02 +02:00
parent 93c9b40931
commit e832d4e63b
8 changed files with 33 additions and 23 deletions

View File

@@ -35,15 +35,15 @@ function getCondition(weatherCode: number | null, rainfall10m: number | null, sn
export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherResponse): ImgwCurrentWeather | null {
if (!payload.data?.Valid || !Array.isArray(payload.data.Data)) return null;
const row = payload.data.Data
const rows = payload.data.Data
.filter((candidate): candidate is RawImgwHybridWeatherRow => {
if (!candidate || typeof candidate !== "object") return false;
return candidate.Type === "Type_Ten_Minutes"
&& typeof candidate.MODEL === "string"
&& candidate.MODEL.includes("AROME")
&& normalizeDate(candidate.Date) !== null;
return candidate.Type === "Type_Ten_Minutes" && normalizeDate(candidate.Date) !== null;
})
.sort((left, right) => String(right.Date).localeCompare(String(left.Date)))[0];
.sort((left, right) => String(left.Date).localeCompare(String(right.Date)));
const fullRow = rows.find((candidate) => typeof candidate.MODEL === "string" && candidate.MODEL.includes("AROME"));
const precipitationRow = rows.find((candidate) => candidate.Precipitation10m !== undefined);
const row = fullRow ?? precipitationRow;
if (!row) return null;
const measuredAt = normalizeDate(row.Date);
@@ -53,6 +53,7 @@ export function normalizeImgwCurrentWeather(payload: RawImgwHybridWeatherRespons
const weatherCode = getWeatherCode(row.Icon10);
return {
coverage: fullRow ? "full" : "precipitation-only",
measuredAt,
temperature: toCelsius(row.Temperature),
feelsLike: toCelsius(row.Chill),