Browse Source

Simple switch timer v2: Mark dp 38 optional in available check.

The check is against null, but the dp was not marked optional, as it
was in the original location.

Update unit test to check the available logic correctly for this file.
Jason Rumney 1 year ago
parent
commit
cca905ae81

+ 1 - 0
custom_components/tuya_local/devices/simple_switch_timerv2.yaml

@@ -49,6 +49,7 @@ secondary_entities:
       - id: 38
       - id: 38
         type: string
         type: string
         name: available
         name: available
+        optional: true
         mapping:
         mapping:
           - dps_val: null
           - dps_val: null
             value: false
             value: false

+ 9 - 0
tests/devices/test_simple_switch_with_timerv2.py

@@ -9,6 +9,7 @@ from .base_device_tests import TuyaDeviceTestCase
 
 
 SWITCH_DPS = "1"
 SWITCH_DPS = "1"
 TIMER_DPS = "9"
 TIMER_DPS = "9"
+INITIAL_STATE_DPS = "38"
 
 
 
 
 class TestTimedSwitch(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
 class TestTimedSwitch(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
@@ -32,3 +33,11 @@ class TestTimedSwitch(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
             self.subject.extra_state_attributes,
             self.subject.extra_state_attributes,
             {},
             {},
         )
         )
+
+    def test_available(self):
+        for id, e in self.entities.items():
+            if id == "select_initial_state":
+                self.dps[INITIAL_STATE_DPS] = None
+                self.assertFalse(e.available)
+                self.dps[INITIAL_STATE_DPS] = "on"
+            self.assertTrue(e.available)