ソースを参照

Add support for Kogan Dehumidifier.

From issue #30
Jason Rumney 5 年 前
コミット
454cae02b0

+ 2 - 1
README.md

@@ -49,6 +49,7 @@ Note that devices sometimes get firmware upgrades, or incompatible versions are
 ### Dehumidifiers
 - Goldair GPDH420 dehumidifiers
 - ElectriQ CD25PRO-LE-V2 dehumidifiers
+- Kogan SmarterHome 7L Desiccant Dehumidifier
 
 ### Humidifiers
 - Eanons QT-JS2014 Purifying Humidifer
@@ -238,6 +239,6 @@ Further device support has been made with the assistance of users.  Please consi
  - [Lapy](https://github.com/Lapy) for contributing support for Electriq dehumidifiers.
  - [thomas-fr](https://github.com/thomas-fr) for contributing support for Poolex Silverline heatpumps.
  - [lperez31](https://github.com/lperez31) for contributing support for Poolex Vertigo heatpumps.
- 
+ - [b3nnyk22](https://github.com/b3nnyk22) for assistance in supporting Kogan Dehumidifiers. 
  
 [![BuyMeCoffee](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/jasonrumney)

+ 78 - 0
custom_components/tuya_local/devices/kogan_dehumidifier.yaml

@@ -0,0 +1,78 @@
+name: "Kogan Dehumidifier"
+primary_entity:
+  entity: humidifier
+  class: dehumidifier
+  dps:
+    - id: 1
+      name: switch
+      type: boolean
+      mapping:
+        - dps_val: false
+          icon: "mdi:air-humidifier-off"
+          icon_priority: 2
+        - dps_val: true
+          icon: "mdi:air-humidifier"
+          icon_priority: 4
+    - id: 2
+      name: mode
+      type: string
+      mapping:
+        - dps_val: low
+          value: Low
+        - dps_val: medium
+          value: Medium
+        - dps_val: high
+          value: High
+        - dps_val: quickdry
+          value: Dry Clothes
+          icon: "mdi:tshirt-crew-outline"
+          icon_priority: 3
+    - id: 3
+      name: current_humidity
+      type: integer
+    - id: 11
+      name: error
+      type: integer
+      readonly: true
+      mapping:
+        - dps_val: 0
+          value: OK
+        - dps_val: 1
+          value: "Tank full"
+          icon: "mdi:cup-water"
+          icon_priority: 1
+    - id: 12
+      name: timer_hr
+      type: integer
+    - id: 13
+      name: timer
+      type: integer
+      readonly: true
+    - id: 101
+      name: humidity
+      type: integer
+      range:
+        min: 0
+        max: 80
+secondary_entities:
+  - entity: fan
+    dps:
+      - id: 1
+        name: switch
+        type: boolean
+      - id: 2
+        name: speed
+        type: string
+        mapping:
+          - dps_val: low
+            value: 33.3
+          - dps_val: medium
+            value: 66.7
+          - dps_val: high
+            value: 100
+          - dps_val: quickdry
+            value: 100
+            invalid: true
+      - id: 8
+        name: oscillate
+        type: boolean

+ 1 - 1
custom_components/tuya_local/manifest.json

@@ -2,7 +2,7 @@
     "domain": "tuya_local",
     "iot_class": "local_polling",
     "name": "Tuya Local",
-    "version": "0.8.6", 
+    "version": "0.8.7",
     "documentation": "https://github.com/make-all/tuya-local",
     "issue_tracker": "https://github.com/make-all/tuya-local/issues",
     "dependencies": [],

+ 11 - 0
tests/const.py

@@ -224,3 +224,14 @@ ELECTRIQ_12WMINV_HEATPUMP_PAYLOAD = {
     "109": 0,
     "110": 0,
 }
+
+KOGAN_DEHUMIDIFIER_PAYLOAD = {
+    "1": True,
+    "2": "low",
+    "3": 70,
+    "8": False,
+    "11": 0,
+    "12": 0,
+    "13": 0,
+    "101": 50,
+}

+ 241 - 0
tests/devices/test_kogan_dehumidifier.py

@@ -0,0 +1,241 @@
+from homeassistant.components.fan import SUPPORT_OSCILLATE, SUPPORT_SET_SPEED
+from homeassistant.components.humidifier import SUPPORT_MODES
+from homeassistant.const import STATE_UNAVAILABLE
+
+from ..const import KOGAN_DEHUMIDIFIER_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DPS = "1"
+MODE_DPS = "2"
+CURRENTHUMID_DPS = "3"
+SWING_DPS = "8"
+ERROR_DPS = "11"
+TIMER_DPS = "12"
+COUNTDOWN_DPS = "13"
+HUMIDITY_DPS = "101"
+
+
+class TestKoganDehumidifier(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("kogan_dehumidifier.yaml", KOGAN_DEHUMIDIFIER_PAYLOAD)
+        self.subject = self.entities.get("humidifier")
+        self.fan = self.entities.get("fan")
+
+    def test_supported_features(self):
+        self.assertEqual(self.subject.supported_features, SUPPORT_MODES)
+        self.assertEqual(
+            self.fan.supported_features,
+            SUPPORT_OSCILLATE | SUPPORT_SET_SPEED,
+        )
+
+    def test_icon(self):
+        """Test that the icon is as expected."""
+        self.dps[SWITCH_DPS] = True
+        self.dps[MODE_DPS] = "low"
+        self.assertEqual(self.subject.icon, "mdi:air-humidifier")
+
+        self.dps[SWITCH_DPS] = False
+        self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
+
+        self.dps[MODE_DPS] = "quickdry"
+        self.assertEqual(self.subject.icon, "mdi:air-humidifier-off")
+
+        self.dps[SWITCH_DPS] = True
+        self.assertEqual(self.subject.icon, "mdi:tshirt-crew-outline")
+
+        self.dps[ERROR_DPS] = 1
+        self.assertEqual(self.subject.icon, "mdi:cup-water")
+
+    def test_min_target_humidity(self):
+        self.assertEqual(self.subject.min_humidity, 0)
+
+    def test_max_target_humidity(self):
+        self.assertEqual(self.subject.max_humidity, 80)
+
+    def test_target_humidity(self):
+        self.dps[HUMIDITY_DPS] = 55
+        self.assertEqual(self.subject.target_humidity, 55)
+
+    def test_is_on(self):
+        self.dps[SWITCH_DPS] = True
+        self.assertTrue(self.subject.is_on)
+        self.assertTrue(self.fan.is_on)
+
+        self.dps[SWITCH_DPS] = False
+        self.assertFalse(self.subject.is_on)
+        self.assertFalse(self.fan.is_on)
+
+        self.dps[SWITCH_DPS] = None
+        self.assertEqual(self.subject.is_on, STATE_UNAVAILABLE)
+        self.assertEqual(self.fan.is_on, STATE_UNAVAILABLE)
+
+    async def test_turn_on(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SWITCH_DPS: True}
+        ):
+            await self.subject.async_turn_on()
+
+    async def test_turn_off(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SWITCH_DPS: False}
+        ):
+            await self.subject.async_turn_off()
+
+    async def test_fan_turn_on(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SWITCH_DPS: True}
+        ):
+            await self.fan.async_turn_on()
+
+    async def test_fan_turn_off(self):
+        async with assert_device_properties_set(
+            self.subject._device, {SWITCH_DPS: False}
+        ):
+            await self.fan.async_turn_off()
+
+    def test_modes(self):
+        self.assertCountEqual(
+            self.subject.available_modes,
+            {
+                "Low",
+                "Medium",
+                "High",
+                "Dry Clothes",
+            },
+        )
+
+    def test_mode(self):
+        self.dps[MODE_DPS] = "low"
+        self.assertEqual(self.subject.mode, "Low")
+        self.dps[MODE_DPS] = "medium"
+        self.assertEqual(self.subject.mode, "Medium")
+        self.dps[MODE_DPS] = "high"
+        self.assertEqual(self.subject.mode, "High")
+        self.dps[MODE_DPS] = "quickdry"
+        self.assertEqual(self.subject.mode, "Dry Clothes")
+
+    async def test_set_mode_to_low(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "low",
+            },
+        ):
+            await self.subject.async_set_mode("Low")
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    async def test_set_mode_to_medium(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "medium",
+            },
+        ):
+            await self.subject.async_set_mode("Medium")
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    async def test_set_mode_to_high(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "high",
+            },
+        ):
+            await self.subject.async_set_mode("High")
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    async def test_set_mode_to_clothes(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "quickdry",
+            },
+        ):
+            await self.subject.async_set_mode("Dry Clothes")
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    def test_fan_speed_steps(self):
+        self.assertEqual(self.fan.speed_count, 3)
+
+    def test_fan_speed(self):
+        self.dps[MODE_DPS] = "low"
+        self.assertAlmostEqual(self.fan.percentage, 33.3, 1)
+        self.dps[MODE_DPS] = "medium"
+        self.assertAlmostEqual(self.fan.percentage, 66.7, 1)
+        self.dps[MODE_DPS] = "high"
+        self.assertEqual(self.fan.percentage, 100)
+        self.dps[MODE_DPS] = "quickdry"
+        self.assertEqual(self.fan.percentage, 100)
+
+    async def test_fan_set_speed_to_low(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "low",
+            },
+        ):
+            await self.fan.async_set_percentage(33)
+
+    async def test_fan_set_speed_to_medium(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "medium",
+            },
+        ):
+            await self.fan.async_set_percentage(66)
+
+    async def test_fan_set_speed_to_high(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                MODE_DPS: "high",
+            },
+        ):
+            await self.fan.async_set_percentage(100)
+
+    def test_fan_oscillating(self):
+        self.dps[SWING_DPS] = True
+        self.assertTrue(self.fan.oscillating)
+
+        self.dps[SWING_DPS] = False
+        self.assertFalse(self.fan.oscillating)
+
+    async def test_set_fan_oscillate_on(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                SWING_DPS: True,
+            },
+        ):
+            await self.fan.async_oscillate(True)
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    async def test_set_fan_oscillate_off(self):
+        async with assert_device_properties_set(
+            self.subject._device,
+            {
+                SWING_DPS: False,
+            },
+        ):
+            await self.fan.async_oscillate(False)
+            self.subject._device.anticipate_property_value.assert_not_called()
+
+    def test_device_state_attributes(self):
+        self.dps[CURRENTHUMID_DPS] = 55
+        self.dps[ERROR_DPS] = 1
+        self.dps[TIMER_DPS] = 3
+        self.dps[COUNTDOWN_DPS] = 160
+        self.assertCountEqual(
+            self.subject.device_state_attributes,
+            {
+                "current_humidity": 55,
+                "error": "Tank full",
+                "timer_hr": 3,
+                "timer": 160,
+            },
+        )
+        self.assertEqual(self.fan.device_state_attributes, {})