Explorar o código

Fix issue where switches without power monitoring were not working.

The missing power dps was causing the swtiches to raise errors during state_attribute creation, leading them to simply not work at all.

Added tests for this.
Jason Rumney %!s(int64=4) %!d(string=hai) anos
pai
achega
1b77775db7

+ 2 - 2
custom_components/tuya_local/generic/switch.py

@@ -39,8 +39,8 @@ 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.")
+        if self._switch_dps is None:
+            raise AttributeError("A switch device must have a switch.")
 
     @property
     def should_poll(self):

+ 3 - 0
tests/devices/test_eanons_humidifier.py

@@ -387,5 +387,8 @@ class TestEanonsHumidifier(IsolatedAsyncioTestCase):
         ):
             await self.switch.async_toggle()
 
+    def test_switch_returns_none_for_power(self):
+        self.assertIsNone(self.switch.current_power_w)
+
     def test_switch_state_attributes_set(self):
         self.assertEqual(self.switch.device_state_attributes, {})

+ 3 - 0
tests/devices/test_purline_m100_heater.py

@@ -371,5 +371,8 @@ class TestPulineM100Heater(IsolatedAsyncioTestCase):
         ):
             await self.switch.async_toggle()
 
+    def test_switch_returns_none_for_power(self):
+        self.assertIsNone(self.switch.current_power_w)
+
     def test_switch_state_attributes_set(self):
         self.assertEqual(self.switch.device_state_attributes, {})