Ver Fonte

YYM aroma nightlight: support GX aroma diffuser also.

This device differs only in the extra fault code, and the strings used
for fan speed.  Use the recently added conditional mapping changes to
handle this.  Since this is the first device using those changes, add
unit tests to ensure the conditional mapping is working.

PR #581
Jason Rumney há 2 anos atrás
pai
commit
721aa70f41

+ 1 - 0
ACKNOWLEDGEMENTS.md

@@ -227,3 +227,4 @@ Further device support has been made with the assistance of users.  Please consi
 - [theshop35](https://github.com/theshop35) for assisting with support for CC curtains.
 - [blakadder](https://github.com/blakadder) for assisting with support for Ultonic K10 air fryer.
 - [szupi-ipuzs](https://github.com/szupi-ipuzs) for contributing support for desk lamps (Setti+ SL601).
+- [MackoMici](https://github.com/MackoMici) for contributing support for GX aroma diffuser, which was merged with the YYM config.

+ 1 - 1
DEVICES.md

@@ -173,7 +173,7 @@
 
 - Asakuki aroma diffuser with light
 - Etersky aroma diffuser with light
-- YYM-805SW aroma diffuser with light
+- YYM-805SW aroma diffuser with light (also supports GX Aroma diffuser)
 
 ### Kitchen Appliances
 

+ 25 - 5
custom_components/tuya_local/devices/yym_805SW_aroma_nightlight.yaml

@@ -1,7 +1,10 @@
 # DPS sample: {'updated_at': 1674433099.9169242, '1': True, '2': 'large', '3': '1', '5': True, '6': 'colourful1', '8': '001fff00e8ffff'}
-name: YYM-805SW Aroma diffuser
+name: Aroma diffuser
 products:
   - id: c0nh3LmEk0NDebrq
+    name: YYM-805SW
+  - id: 4870500398f4abbfbae4
+    name: GX
 primary_entity:
   entity: fan
   dps:
@@ -19,10 +22,27 @@ primary_entity:
       name: speed
       type: string
       mapping:
-        - dps_val: large
-          value: 100
-        - dps_val: small
-          value: 50
+        - conditions:
+            - dps_val:
+                - large
+                - small
+              mapping:
+                - dps_val: large
+                  value: 100
+                - dps_val: small
+                  value: 50
+            - dps_val:
+                - high
+                - low
+              mapping:
+                - dps_val: high
+                  value: 100
+                - dps_val: low
+                  value: 50
+    - id: 9
+      name: fault_code
+      type: bitfield
+      optional: true
 secondary_entities:
   - entity: light
     name: Nightlight

+ 11 - 0
tests/const.py

@@ -1559,3 +1559,14 @@ BCOM_CAMERA_PAYLOAD = {
     "231": "",
     "232": False,
 }
+
+GX_AROMA_PAYLOAD = {
+    "1": True,
+    "2": "high",
+    "3": "cancel",
+    "4": 0,
+    "5": True,
+    "6": "colour",
+    "8": "b9fff500ab46ff",
+    "9": 0,
+}

+ 67 - 0
tests/devices/test_gx_aroma_diffuser.py

@@ -0,0 +1,67 @@
+# Test the multi-model config for YYM/GX aroma diffusers - specifically
+# the conditional mapping of fan speed to either high/low or large/small.
+from ..const import GX_AROMA_PAYLOAD
+from ..helpers import assert_device_properties_set
+from .base_device_tests import TuyaDeviceTestCase
+
+FANSWITCH_DP = "1"
+FANSPEED_DP = "2"
+TIMER_DP = "3"
+REMAIN_DP = "4"
+LIGHTSWITCHDP = "5"
+LIGHTMODE_DP = "6"
+LIGHTCOLOR_DP = "8"
+ERROR_DP = "9"
+
+
+class TestAromaDiffuser(TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig("yym_805SW_aroma_nightlight.yaml", GX_AROMA_PAYLOAD)
+        self.subject = self.entities["fan"]
+        self.mark_secondary(["select_timer"])
+
+    def test_speed_step(self):
+        # YYM diffuser
+        self.dps[FANSPEED_DP] = "large"
+        self.assertEqual(self.subject.percentage_step, 50)
+        self.assertEqual(self.subject.speed_count, 2)
+        self.dps[FANSPEED_DP] = "small"
+        self.assertEqual(self.subject.percentage_step, 50)
+        self.assertEqual(self.subject.speed_count, 2)
+        # GX diffuser
+        self.dps[FANSPEED_DP] = "high"
+        self.assertEqual(self.subject.percentage_step, 50)
+        self.assertEqual(self.subject.speed_count, 2)
+        self.dps[FANSPEED_DP] = "high"
+        self.assertEqual(self.subject.percentage_step, 50)
+        self.assertEqual(self.subject.speed_count, 2)
+
+    def test_speed(self):
+        # YYM diffuser
+        self.dps[FANSPEED_DP] = "large"
+        self.assertEqual(self.subject.percentage, 100)
+        self.dps[FANSPEED_DP] = "small"
+        self.assertEqual(self.subject.percentage, 50)
+        # GX diffuser
+        self.dps[FANSPEED_DP] = "high"
+        self.assertEqual(self.subject.percentage, 100)
+        self.dps[FANSPEED_DP] = "low"
+        self.assertEqual(self.subject.percentage, 50)
+
+    async def test_set_fan_speed_yym(self):
+        self.dps[FANSPEED_DP] = "large"
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FANSPEED_DP: "small"},
+        ):
+            await self.subject.async_set_percentage(50)
+
+    async def test_set_fan_speed_gx(self):
+        self.dps[FANSPEED_DP] = "high"
+        async with assert_device_properties_set(
+            self.subject._device,
+            {FANSPEED_DP: "low"},
+        ):
+            await self.subject.async_set_percentage(50)