4
0
Эх сурвалжийг харах

Add support for DS02-F fan switches (Treatlife)

Issue #316
Jason Rumney 3 жил өмнө
parent
commit
ae0510bc3c

+ 1 - 0
ACKNOWLEDGEMENTS.md

@@ -151,3 +151,4 @@ Further device support has been made with the assistance of users.  Please consi
 - [cnrd](https://github.com/cnrd) for contributing support for Eeese Otto dehumidifiers.
 - [markwellis](https://github.com/markwellis) for contributing support for Eurom Sani Wall Heat 2000 heaters.
 - [escoand](https://github.com/escoand) for contributing support for Tellur USB power strip.
+- [BrettEBowman](https://github.com/BrettEBowman) for assistance supporting Treatlife DS02-F fans.

+ 1 - 0
DEVICES.md

@@ -99,6 +99,7 @@
 - Lexy F501 fan
 - Stirling FS1-40DC pedestal fan
 - TMWF02 fan controller
+- Treatlife DS02-F fan switch
 
 ### Air Purifiers
 

+ 41 - 0
custom_components/tuya_local/devices/treatlife_ds02_fan.yaml

@@ -0,0 +1,41 @@
+name: DS02-F fan switch
+product:
+  - id: qmijt70hk4op6snl
+primary_entity:
+  entity: fan
+  dps:
+    - id: 1
+      type: boolean
+      name: switch
+    - id: 3
+      type: string
+      name: speed
+      mapping:
+        - dps_val: level_1
+          value: 25
+          step: 25
+        - dps_val: level_2
+          value: 50
+          step: 25
+        - dps_val: level_3
+          value: 75
+          step: 25
+        - dps_val: level_4
+          value: 100
+          step: 25
+secondary_entities:
+  - entity: number
+    name: Timer
+    category: config
+    icon: "mdi:timer"
+    dps:
+      - id: 2
+        type: integer
+        name: value
+        unit: min
+        range:
+          min: 0
+          max: 86400
+        mapping:
+          - scale: 60
+            step: 60

+ 6 - 0
tests/const.py

@@ -1518,3 +1518,9 @@ HYDROTHERM_DYNAMICX8_PAYLOAD = {
     "4": "STANDARD",
     "21": 0,
 }
+
+TREATLIFE_DS02F_PAYLOAD = {
+    "1": True,
+    "2": 0,
+    "3": "level_2",
+}

+ 55 - 0
tests/devices/test_treatlife_ds02f.py

@@ -0,0 +1,55 @@
+from homeassistant.components.fan import FanEntityFeature
+from homeassistant.const import TIME_MINUTES
+
+from ..const import TREATLIFE_DS02F_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.number import BasicNumberTests
+from ..mixins.switch import SwitchableTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DPS = "1"
+TIMER_DPS = "2"
+SPEED_DPS = "3"
+
+
+class TestTreatlifeFan(SwitchableTests, BasicNumberTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("treatlife_ds02_fan.yaml", TREATLIFE_DS02F_PAYLOAD)
+        self.subject = self.entities["fan"]
+        self.setUpSwitchable(SWITCH_DPS, self.subject)
+        self.setUpBasicNumber(
+            TIMER_DPS,
+            self.entities.get("number_timer"),
+            max=1440.0,
+            scale=60,
+            unit=TIME_MINUTES,
+        )
+        self.mark_secondary(["number_timer"])
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            FanEntityFeature.SET_SPEED,
+        )
+
+    def test_speed(self):
+        self.dps[SPEED_DPS] = "level_2"
+        self.assertEqual(self.subject.percentage, 50)
+
+    def test_speed_step(self):
+        self.assertEqual(self.subject.percentage_step, 25)
+        self.assertEqual(self.subject.speed_count, 4)
+
+    async def test_set_speed(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SPEED_DPS: "level_3"}
+        ):
+            await self.subject.async_set_percentage(75)
+
+    async def test_set_speed_snaps(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SPEED_DPS: "level_1"}
+        ):
+            await self.subject.async_set_percentage(30)