Răsfoiți Sursa

Add support for Himox H05 Purifier

Issue #142
Jason Rumney 3 ani în urmă
părinte
comite
7d220c270a

+ 1 - 1
ACKNOWLEDGEMENTS.md

@@ -83,4 +83,4 @@ Further device support has been made with the assistance of users.  Please consi
 - [tavicu](https://github.com/tavicu) for contributing support for Starlight Heatpumps, and for the idea to support inverted values.
 - [Chris061290](https://github.com/Chris061290) for contributing support for IPS Pro pool heatpumps, complete with unit tests.
 - [MartinCarbol](https://github.com/MartinCarbol) for contributing support for two models of Tesla Air Purifier.
-
+- [gschmidl](https://github.com/gschmidl) for assistance with Himox H05 purifiers

+ 1 - 1
README.md

@@ -100,7 +100,7 @@ the device will not work despite being listed below.
 ### Air Purifiers
 - Renpho RP-AP001S air purifier
 - Poiema One air purifier
-- Himox H06 air purifier
+- Himox H05 and H06 air purifiers
 - Tesla Pro and Mini air purifiers
 - Vork VK6067AW air purifier
 

+ 81 - 0
custom_components/tuya_local/devices/himox_h05_purifier.yaml

@@ -0,0 +1,81 @@
+name: Himox H05 Air Purifier
+primary_entity:
+  entity: fan
+  dps:
+    - id: 1
+      type: boolean
+      name: switch
+    - id: 4
+      type: string
+      name: preset_mode
+      mapping:
+        - dps_val: auto
+          value: auto
+        - dps_val: low
+          value: low
+        - dps_val: mid
+          value: mid
+        - dps_val: high
+          value: high
+secondary_entities:
+  - entity: sensor
+    name: Current Temperature
+    class: temperature
+    category: diagnostic
+    dps:
+      - id: 2
+        type: integer
+        name: sensor
+        unit: C
+        class: measurement
+  - entity: sensor
+    name: Active Filter Life
+    icon: "mdi:air-filter"
+    category: diagnostic
+    dps:
+      - id: 5
+        type: integer
+        name: sensor
+        readonly: true
+        unit: "%"
+  - entity: lock
+    name: Child Lock
+    category: config
+    dps:
+      - id: 7
+        type: boolean
+        name: lock
+        mapping:
+          - dps_val: true
+            icon: "mdi:hand-back-right-off"
+          - dps_val: false
+            icon: "mdi:hand-back-right"
+  - entity: switch
+    name: Filter Reset
+    category: config
+    dps:
+      - id: 11
+        type: boolean
+        name: switch
+  - entity: select
+    name: Timer
+    icon: "mdi:timer"
+    category: config
+    dps:
+      - id: 18
+        name: option
+        type: string
+        mapping:
+          - dps_val: cancel
+            value: "Off"
+          - dps_val: 4h
+            value: "4 hours"
+          - dps_val: 8h
+            value: "8 hours"
+  - entity: sensor
+    name: Air Quality
+    dps:
+      - id: 21
+        type: string
+        name: sensor
+        readonly: true

+ 11 - 0
tests/const.py

@@ -1034,6 +1034,17 @@ HIMOX_H06_PURIFIER_PAYLOAD = {
     "101": "calcle",
 }
 
+HIMOX_H05_PURIFIER_PAYLOAD = {
+    "1": True,
+    "2": 21,
+    "4": "auto",
+    "5": 92,
+    "7": False,
+    "11": False,
+    "18": "cancel",
+    "21": "good",
+}
+
 VORK_VK6067_PURIFIER_PAYLOAD = {
     "1": True,
     "4": "auto",

+ 105 - 0
tests/devices/test_himox_h05_purifier.py

@@ -0,0 +1,105 @@
+from homeassistant.components.fan import SUPPORT_PRESET_MODE
+from homeassistant.components.sensor import (
+    DEVICE_CLASS_TEMPERATURE,
+    STATE_CLASS_MEASUREMENT,
+)
+from homeassistant.const import (
+    PERCENTAGE,
+    TEMP_CELSIUS,
+    TIME_MINUTES,
+)
+
+from ..const import HIMOX_H05_PURIFIER_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.lock import BasicLockTests
+from ..mixins.select import BasicSelectTests
+from ..mixins.sensor import MultiSensorTests
+from ..mixins.switch import BasicSwitchTests, SwitchableTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DPS = "1"
+TEMP_DPS = "2"
+PRESET_DPS = "4"
+FILTER_DPS = "5"
+LOCK_DPS = "7"
+RESET_DPS = "11"
+TIMER_DPS = "18"
+AQI_DPS = "21"
+
+
+class TestHimoxH05Purifier(
+    BasicLockTests,
+    BasicSwitchTests,
+    BasicSelectTests,
+    MultiSensorTests,
+    SwitchableTests,
+    TuyaDeviceTestCase,
+):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("himox_h05_purifier.yaml", HIMOX_H05_PURIFIER_PAYLOAD)
+        self.subject = self.entities["fan"]
+        self.setUpSwitchable(SWITCH_DPS, self.subject)
+        self.setUpBasicLock(LOCK_DPS, self.entities.get("lock_child_lock"))
+        self.setUpBasicSelect(
+            TIMER_DPS,
+            self.entities.get("select_timer"),
+            {
+                "cancel": "Off",
+                "4h": "4 hours",
+                "8h": "8 hours",
+            },
+        )
+        self.setUpBasicSwitch(RESET_DPS, self.entities.get("switch_filter_reset"))
+        self.setUpMultiSensors(
+            [
+                {
+                    "dps": TEMP_DPS,
+                    "name": "sensor_current_temperature",
+                    "unit": TEMP_CELSIUS,
+                    "device_class": DEVICE_CLASS_TEMPERATURE,
+                    "state_class": STATE_CLASS_MEASUREMENT,
+                },
+                {
+                    "dps": FILTER_DPS,
+                    "name": "sensor_active_filter_life",
+                    "unit": PERCENTAGE,
+                },
+                {
+                    "dps": AQI_DPS,
+                    "name": "sensor_air_quality",
+                },
+            ]
+        )
+        self.mark_secondary(
+            [
+                "lock_child_lock",
+                "switch_filter_reset",
+                "sensor_active_filter_life",
+                "select_timer",
+                "sensor_current_temperature",
+            ]
+        )
+
+    def test_supported_features(self):
+        self.assertEqual(
+            self.subject.supported_features,
+            SUPPORT_PRESET_MODE,
+        )
+
+    def test_preset_modes(self):
+        self.assertCountEqual(
+            self.subject.preset_modes,
+            ["auto", "low", "mid", "high"],
+        )
+
+    def test_preset_mode(self):
+        self.dps[PRESET_DPS] = "low"
+        self.assertEqual(self.subject.preset_mode, "low")
+
+    async def test_set_preset_mode(self):
+        async with assert_device_properties_set(
+            self.subject._device, {PRESET_DPS: "mid"}
+        ):
+            await self.subject.async_set_preset_mode("mid")