소스 검색

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

Jason Rumney 4 년 전
부모
커밋
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."""