Parcourir la source

Add a second simple switch with timer.

Based on PR #208 for Nexxt 220V smartplug

Decided to make this generic, as dp 9 is commonly used for timer in other devices (though switches seem to prefer 11 for some reason, I think because it makes a nice gap of 10 between the corresponding switch and timer in multiswitch devices).
Jason Rumney il y a 3 ans
Parent
commit
3f13b9aefe

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

@@ -0,0 +1,27 @@
+name: Simple Switch With Timer
+products:
+  - id: eetmtcempdyxgpx5
+    name: Nexxt 220v SmartPlug
+primary_entity:
+  entity: switch
+  class: outlet
+  dps:
+    - id: 1
+      name: switch
+      type: boolean
+secondary_entities:
+  - entity: number
+    category: config
+    name: Timer
+    icon: "mdi:timer"
+    dps:
+      - id: 9
+        name: value
+        type: integer
+        unit: min
+        range:
+          min: 0
+          max: 86400
+        mapping:
+          - scale: 60
+            step: 60

+ 5 - 0
tests/const.py

@@ -831,6 +831,11 @@ TIMED_SOCKET_PAYLOAD = {
     "11": 0,
 }
 
+TIMED_SOCKETV2_PAYLOAD = {
+    "1": True,
+    "9": 0,
+}
+
 DIGOO_DGSP202_SOCKET_PAYLOAD = {
     "1": True,
     "2": True,

+ 37 - 0
tests/devices/test_simple_switch_with_timerv2.py

@@ -0,0 +1,37 @@
+"""Tests for a simple switch with timer"""
+from homeassistant.components.switch import SwitchDeviceClass
+from homeassistant.const import TIME_MINUTES
+
+from ..const import TIMED_SOCKETV2_PAYLOAD
+from ..mixins.number import BasicNumberTests
+from ..mixins.switch import SwitchableTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DPS = "1"
+TIMER_DPS = "9"
+
+
+class TestTimedSwitch(BasicNumberTests, SwitchableTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("simple_switch_timerv2.yaml", TIMED_SOCKETV2_PAYLOAD)
+        self.subject = self.entities.get("switch")
+        self.setUpSwitchable(SWITCH_DPS, self.subject)
+        self.setUpBasicNumber(
+            TIMER_DPS,
+            self.entities.get("number_timer"),
+            max=1440,
+            scale=60,
+            unit=TIME_MINUTES,
+        )
+        self.mark_secondary(["number_timer"])
+
+    def test_device_class_is_outlet(self):
+        self.assertEqual(self.subject.device_class, SwitchDeviceClass.OUTLET)
+
+    def test_extra_state_attributes_set(self):
+        self.assertDictEqual(
+            self.subject.extra_state_attributes,
+            {},
+        )