Fix weather city name getting wiped on every settings save

The city text field isn't pre-filled with the current value (unlike
the manual lat/lon fields below it), so it's blank on every
settings-only save -- changing forecast_days, a display toggle, etc.
That fell into the branch that unconditionally set "city": "", so the
resolved city name silently disappeared on every save even though
lat/lon round-tripped fine (those fields *are* pre-filled).

Now only clears the city label when the submitted coordinates
actually differ from what's stored. Verified both directions end to
end: city survives a settings-only save, and still clears correctly
when coordinates are genuinely changed.
This commit is contained in:
Honey committed 2026-07-25 10:42:50 +02:00
1 parent 11c03c86b1
commit 45fb370279
1 file changed
+13 -3
+13 -3
View File
@@ -98,10 +98,20 @@ def create_app(config, screens: dict, scheduler) -> Flask:
scheduler.invalidate_screen("weather") scheduler.invalidate_screen("weather")
return redirect(url_for("settings_weather", saved=1)) return redirect(url_for("settings_weather", saved=1))
else: else:
# The city text field isn't pre-filled (unlike the manual
# lat/lon fields below it), so it's blank on every
# settings-only save -- toggles, forecast_days, etc. Only
# clear the resolved city label when the coordinates
# actually changed; otherwise this would silently wipe the
# city on every save even though lat/lon round-trip fine.
current = config.get_screen_settings("weather")
new_lat = float(lat_raw) if lat_raw else None
new_lon = float(lon_raw) if lon_raw else None
coords_unchanged = new_lat == current.get("latitude") and new_lon == current.get("longitude")
config.update_screen_settings("weather", { config.update_screen_settings("weather", {
"city": "", "city": current.get("city", "") if coords_unchanged else "",
"latitude": float(lat_raw) if lat_raw else None, "latitude": new_lat,
"longitude": float(lon_raw) if lon_raw else None, "longitude": new_lon,
"forecast_days": forecast_days, "forecast_days": forecast_days,
"update_minutes": update_minutes, "update_minutes": update_minutes,
**display_toggles, **display_toggles,