Sfoglia il codice sorgente

fix(alarm_control_panel): handle no data received for alarm_state

When no data has been received from the device, alarm_state can be legitimately None
In this case avoid a ValueError caused by coercing it to AlarmControlPanelState,
and allow it to show naturally as "Unknown".

Issue #5088
Jason Rumney 2 giorni fa
parent
commit
5b9a5e0342
1 ha cambiato i file con 5 aggiunte e 3 eliminazioni
  1. 5 3
      custom_components/tuya_local/alarm_control_panel.py

+ 5 - 3
custom_components/tuya_local/alarm_control_panel.py

@@ -72,9 +72,11 @@ class TuyaLocalAlarmControlPanel(TuyaLocalEntity, AlarmControlPanelEntity):
         """Return the current alarm state."""
         """Return the current alarm state."""
         if self._trigger_dp and self._trigger_dp.get_value(self._device):
         if self._trigger_dp and self._trigger_dp.get_value(self._device):
             return AlarmControlPanelState.TRIGGERED
             return AlarmControlPanelState.TRIGGERED
-        return AlarmControlPanelState(
-            self._alarm_state_dp.get_value(self._device),
-        )
+        raw_state = self._alarm_state_dp.get_value(self._device)
+        if raw_state is not None:
+            return AlarmControlPanelState(
+                self._alarm_state_dp.get_value(self._device),
+            )
 
 
     async def _alarm_send_command(self, cmd: str):
     async def _alarm_send_command(self, cmd: str):
         async with self._device.set_lock:
         async with self._device.set_lock: