Преглед на файлове

Fix /services non-dict response crashing ApiHealthSensor

ZiB преди 4 месеца
родител
ревизия
5846f84525
променени са 2 файла, в които са добавени 6 реда и са изтрити 2 реда
  1. 5 1
      custom_components/room_cal_ha/backends/api.py
  2. 1 1
      custom_components/room_cal_ha/sensor.py

+ 5 - 1
custom_components/room_cal_ha/backends/api.py

@@ -83,7 +83,11 @@ class RoomCalApiBackend(ReservationBackend):
     try:
       async with session.get(f"{self._base_url()}/services", headers=self._headers()) as resp:
         if resp.status == 200:
-          services = await resp.json()
+          raw = await resp.json()
+          if isinstance(raw, dict):
+            services = raw
+          else:
+            _LOGGER.warning("Unexpected /services response (expected dict, got %s)", type(raw).__name__)
     except Exception as exc:
       _LOGGER.warning("Failed to fetch /services: %s", exc)
 

+ 1 - 1
custom_components/room_cal_ha/sensor.py

@@ -278,6 +278,6 @@ class ApiHealthSensor(CoordinatorEntity[RoomCalCoordinator], SensorEntity):
   @property
   def extra_state_attributes(self) -> dict | None:
     api_status = self.coordinator.data.api_status
-    if api_status is None or not api_status.services:
+    if api_status is None or not isinstance(api_status.services, dict) or not api_status.services:
       return None
     return dict(api_status.services)