Răsfoiți Sursa

Add info-level activity logging for reservation changes, patches, and overrides

Backend/lock/wifi debug and warning logging was already solid, but reservation
state transitions, thin-update patches, and override start/end were silent.
Also drops redundant before/after log pairs for check-in/check-out actions in
favor of a single after-the-fact key=value line, and standardizes message
style away from quoted prose.
ZiB 3 luni în urmă
părinte
comite
d3c419b396
1 a modificat fișierele cu 16 adăugiri și 8 ștergeri
  1. 16 8
      custom_components/room_cal_ha/coordinator.py

+ 16 - 8
custom_components/room_cal_ha/coordinator.py

@@ -189,6 +189,10 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
     if old_current != new_current:
       self._current_last_updated = now
       await self.store.async_set_last_updated(STORE_CURRENT, now)
+      _LOGGER.info(
+        "Current reservation changed: guest=%s check_in=%s check_out=%s",
+        new_current.guest_name, new_current.check_in_date, new_current.check_out_date,
+      )
     if old_next != new_next:
       self._next_last_updated = now
       await self.store.async_set_last_updated(STORE_NEXT, now)
@@ -207,6 +211,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
         backend_current, backend_next = await backend.async_fetch()
         backend_fetched = True
       except BackendAuthError:
+        _LOGGER.warning("Reauth triggered: sync_mode=%s", sync_mode)
         self.entry.async_start_reauth(self.hass)
         raise UpdateFailed("CalDAV authorization failed; re-auth required")
       except BackendConnectError as exc:
@@ -218,6 +223,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
         backend_current, backend_next = await api_backend.async_fetch()
         backend_fetched = True
       except BackendAuthError:
+        _LOGGER.warning("Reauth triggered: sync_mode=%s", sync_mode)
         self.entry.async_start_reauth(self.hass)
         raise UpdateFailed("API authorization failed; re-auth required")
       except BackendConnectError as exc:
@@ -317,21 +323,19 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
   async def _async_run_check_in_actions(self, res: ReservationData) -> None:
     """Run WiFi + lock updates and guest mode activation. No-op when mode_sync is off."""
     if not self._is_mode_sync_on():
+      _LOGGER.debug("Check-in skipped: mode_sync=off guest=%s", res.guest_name)
       return
-    _LOGGER.info("Check-in: guest=%s", res.guest_name)
     if self._is_use_unifi_on() and isinstance(res.wifi_ssid, str):
       from .wifi import async_set_ssid_enabled, async_set_wifi_key
       try:
-        _LOGGER.info("WiFi on: enabling SSID '%s'", res.wifi_ssid)
         await async_set_ssid_enabled(self.hass, res.wifi_ssid, True)
-        _LOGGER.info("WiFi on: SSID '%s' enabled", res.wifi_ssid)
+        _LOGGER.info("WiFi enabled: ssid=%s", res.wifi_ssid)
       except Exception as err:
         _LOGGER.warning("Failed to enable SSID '%s': %s", res.wifi_ssid, err)
       if isinstance(res.wifi_key, str):
         try:
-          _LOGGER.info("WiFi on: setting key for SSID '%s'", res.wifi_ssid)
           await async_set_wifi_key(self.hass, res.wifi_ssid, res.wifi_key)
-          _LOGGER.info("WiFi on: key set for SSID '%s'", res.wifi_ssid)
+          _LOGGER.info("WiFi key set: ssid=%s", res.wifi_ssid)
         except Exception as err:
           _LOGGER.warning("Failed to set WiFi key: %s", err)
     if self._is_use_zwave_on() and isinstance(res.door_code, str):
@@ -343,14 +347,13 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
   async def _async_run_check_out_actions(self, res: ReservationData) -> None:
     """Run WiFi SSID disable, lock slot disable, and guest mode deactivation. No-op when mode_sync is off."""
     if not self._is_mode_sync_on():
+      _LOGGER.debug("Check-out skipped: mode_sync=off guest=%s", res.guest_name)
       return
-    _LOGGER.info("Check-out: guest=%s", res.guest_name)
     if self._is_use_unifi_on() and isinstance(res.wifi_ssid, str):
       from .wifi import async_set_ssid_enabled
       try:
-        _LOGGER.info("WiFi off: disabling SSID '%s'", res.wifi_ssid)
         await async_set_ssid_enabled(self.hass, res.wifi_ssid, False)
-        _LOGGER.info("WiFi off: SSID '%s' disabled", res.wifi_ssid)
+        _LOGGER.info("WiFi disabled: ssid=%s", res.wifi_ssid)
       except Exception as err:
         _LOGGER.warning("Failed to disable SSID '%s': %s", res.wifi_ssid, err)
     if self._is_use_zwave_on():
@@ -384,6 +387,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
     nxt = self.store.get(STORE_NEXT) or self._empty_reservation()
 
     if self._reservation_window_state(nxt) in ("active", "elapsed"):
+      _LOGGER.info("Reconcile: promoted next to current guest=%s", nxt.guest_name)
       await self.store.async_set(STORE_CURRENT, nxt)
       await self._async_maybe_reset_arrival_flags(old_current, nxt)
       self._current_last_refresh = dt_util.utcnow()
@@ -392,6 +396,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
 
     state = self._reservation_window_state(current)
     if state == "elapsed":
+      _LOGGER.info("Reconcile: cleared elapsed current guest=%s", current.guest_name)
       await self.store.async_set(STORE_CURRENT, None)
       await self._async_maybe_reset_arrival_flags(old_current, None)
       self._current_last_refresh = dt_util.utcnow()
@@ -493,6 +498,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
     self._cancel_override_end_timer()
     old_current = self._effective(STORE_CURRENT)
     self._override = override
+    _LOGGER.info("Override started: guest=%s end_at=%s", override.current.guest_name, end_at)
     now = dt_util.utcnow()
     self._current_last_refresh = now
     if override.next is not None:
@@ -518,6 +524,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
     if self._override is None:
       return
     old_current = self._override.current
+    _LOGGER.info("Override ended: guest=%s", old_current.guest_name)
     await self._reconcile_store_elapsed()
     self._override = None
     new_current = self._effective(STORE_CURRENT)
@@ -529,6 +536,7 @@ class RoomCalCoordinator(DataUpdateCoordinator[CoordinatorData]):
 
   async def async_apply_update(self, target: str, partial: dict[str, Any]) -> None:
     """Apply a thin update (service call) to whichever layer owns `target`."""
+    _LOGGER.info("Patch applied: target=%s fields=%s", target, sorted(partial))
     new_value = self._effective(target).apply_partial(partial)
     diff = await self._async_transition(target, new_value)
     if diff: