Просмотр исходного кода

Ensure _power_dps and _switch_dps are created, even if they are None.

Jason Rumney 4 лет назад
Родитель
Сommit
fac79e8c33
1 измененных файлов с 5 добавлено и 0 удалено
  1. 5 0
      custom_components/tuya_local/generic/switch.py

+ 5 - 0
custom_components/tuya_local/generic/switch.py

@@ -27,6 +27,8 @@ class TuyaLocalSwitch(SwitchEntity):
         """
         self._device = device
         self._config = config
+        self._switch_dps = None
+        self._power_dps = None
         self._attr_dps = []
         for d in config.dps():
             if d.name == "switch":
@@ -37,6 +39,9 @@ class TuyaLocalSwitch(SwitchEntity):
                 if not d.hidden:
                     self._attr_dps.append(d)
 
+    if self._switch_dps is None:
+        raise AttributeError("A switch device must have a switch.")
+
     @property
     def should_poll(self):
         """Return the polling state."""