Преглед изворни кода

Prefer locally stored codes over upstream on reservation updates

wifi_key, wifi_ssid, and door_code now follow the same priority: stored
value wins, upstream value is only used on first import when nothing is
stored yet.
ZiB пре 4 месеци
родитељ
комит
e3f032e0b6
1 измењених фајлова са 5 додато и 3 уклоњено
  1. 5 3
      room_cal/reservations/__init__.py

+ 5 - 3
room_cal/reservations/__init__.py

@@ -47,9 +47,11 @@ class Reservation(StoreBacked, EventSource):
 
     existing_xd = safe_json_loads(existing.x_data) if existing else None
     defaults = _reservation_defaults()
-    wk = data.get('wifi_key') or (existing_xd or {}).get('wifi_key') or defaults.wifi_key or _gen_wifi_key()
-    ws = data.get('wifi_ssid') or (existing_xd or {}).get('wifi_ssid') or defaults.wifi_ssid
-    dc = data.get('door_code') or (existing_xd or {}).get('door_code') or defaults.door_code or _gen_door_code()
+    # Stored value wins over upstream: first import picks up the upstream value, subsequent updates keep local.
+    xd = existing_xd or {}
+    wk = xd.get('wifi_key') or data.get('wifi_key') or defaults.wifi_key or _gen_wifi_key()
+    ws = xd.get('wifi_ssid') or data.get('wifi_ssid') or defaults.wifi_ssid
+    dc = xd.get('door_code') or data.get('door_code') or defaults.door_code or _gen_door_code()
 
     x_data_dict = {k: data.get(k) for k in ['guest_name', 'service', 'reservation_id']}
     x_data_dict['service_data'] = data.get('service_data') or {}