diff --git a/shell/plugins/panels/weather/Model.js b/shell/plugins/panels/weather/Model.js index 8d122c47..02a49935 100644 --- a/shell/plugins/panels/weather/Model.js +++ b/shell/plugins/panels/weather/Model.js @@ -194,6 +194,12 @@ function currentIcon(current, fallback) { return fallback || "" } +// wttr.in has no day/night flag. Use its icon only to fill an empty initial +// state, never to replace a day/night-aware icon resolved by Open-Meteo. +function provisionalCurrentIcon(current, resolvedIcon) { + return resolvedIcon || currentIcon(current, "") +} + function weatherResponseCompletesSave(hasConfiguredCoordinates, source) { return hasConfiguredCoordinates ? source === "open-meteo" : source === "wttr" } @@ -290,6 +296,7 @@ if (typeof module !== "undefined") { openMeteoForecastDays: openMeteoForecastDays, openMeteoCurrentCondition: openMeteoCurrentCondition, currentIcon: currentIcon, + provisionalCurrentIcon: provisionalCurrentIcon, weatherResponseCompletesSave: weatherResponseCompletesSave, wttrNextForecastDays: wttrNextForecastDays, buildForecastDays: buildForecastDays, diff --git a/shell/plugins/panels/weather/Panel.qml b/shell/plugins/panels/weather/Panel.qml index d12c5d18..b119018e 100644 --- a/shell/plugins/panels/weather/Panel.qml +++ b/shell/plugins/panels/weather/Panel.qml @@ -315,7 +315,7 @@ Panel { var parsed = JSON.parse(raw) root.report = parsed if (!root.hasConfiguredCoordinates) - root.label = Model.currentIcon(parsed.current_condition && parsed.current_condition[0], root.label) + root.label = Model.provisionalCurrentIcon(parsed.current_condition && parsed.current_condition[0], root.label) root.forecastRetries = 0 if (Model.weatherResponseCompletesSave(root.hasConfiguredCoordinates, "wttr")) root.finishSavingLocation() diff --git a/test/shell.d/weather-test.sh b/test/shell.d/weather-test.sh index c31790dd..5b2aab46 100644 --- a/test/shell.d/weather-test.sh +++ b/test/shell.d/weather-test.sh @@ -112,6 +112,8 @@ assert(weather.dayIcon({ openMeteoWeatherCode: 95 }).length > 0, 'weather maps O assertEqual(weather.currentIcon({ openMeteoWeatherCode: 0, isDay: 1 }, ''), weather.iconForOpenMeteoCode(0), 'weather uses the current Open-Meteo icon with current values') assertEqual(weather.currentIcon({ openMeteoWeatherCode: 0, isDay: 0 }, ''), weather.iconForCode(113, true), 'weather uses the nighttime Open-Meteo icon after sunset') assert(weather.iconForOpenMeteoCode(45, true) !== weather.iconForOpenMeteoCode(45, false), 'weather distinguishes nighttime fog from daytime fog') +assertEqual(weather.provisionalCurrentIcon({ weatherCode: 113 }, ''), weather.iconForCode(113, false), 'weather uses wttr to fill an empty initial icon') +assertEqual(weather.provisionalCurrentIcon({ weatherCode: 113 }, 'night'), 'night', 'weather refresh preserves a resolved day-night icon') assert( fs.readFileSync(root + '/shell/plugins/panels/weather/Panel.qml', 'utf8').includes('text: root.label || "—"'), 'weather hero and bar use the same resolved icon'