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:
1 parent
11c03c86b1
commit
45fb370279
1 file changed
+13
-3
+13
-3
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user