From 45fb37027991c0551d1693261c00315be9eb9e34 Mon Sep 17 00:00:00 2001 From: Honey Date: Sat, 25 Jul 2026 10:42:50 +0200 Subject: [PATCH] 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. --- web/app.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/web/app.py b/web/app.py index a16a0bb..e8fdf42 100644 --- a/web/app.py +++ b/web/app.py @@ -98,10 +98,20 @@ def create_app(config, screens: dict, scheduler) -> Flask: scheduler.invalidate_screen("weather") return redirect(url_for("settings_weather", saved=1)) 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", { - "city": "", - "latitude": float(lat_raw) if lat_raw else None, - "longitude": float(lon_raw) if lon_raw else None, + "city": current.get("city", "") if coords_unchanged else "", + "latitude": new_lat, + "longitude": new_lon, "forecast_days": forecast_days, "update_minutes": update_minutes, **display_toggles,