Parcourir la source

GPDH340 dehumidifier: add hidden Custom mode.

- add handling of hidden mappings in device config parser.  Intention
is to allow them to map, but hide them from the list of values for the
user to select.

Issue #727
Jason Rumney il y a 2 ans
Parent
commit
4fd03b1106

+ 11 - 0
custom_components/tuya_local/devices/README.md

@@ -293,6 +293,17 @@ different than the DP value from the Tuya protocol.  Normally it will be used
 with `dps_val` to map from one value to another. It could also be used at top
 level to override all values, but I can't imagine a useful purpose for that.
 
+### `hidden`
+
+*Optional, default=false*
+
+When set to true, the mapping value is hidden from the list of all values.
+This can be used for items that should not be available for selection by the
+user but you still want to map for feedback coming from the device.  For
+example, some devices have a "Manual" mode, which is automatically selected
+when adjustments are made to other settings, but should not be available as
+an explicit mode for the user to select.
+
 ### `scale`
 
 *Optional, default=1.*

+ 3 - 0
custom_components/tuya_local/devices/goldair_gpdh340_dehumidifier.yaml

@@ -20,6 +20,9 @@ primary_entity:
       name: mode
       type: string
       mapping:
+        - dps_val: "2"
+          value: Custom
+          hidden: true
         - dps_val: "4"
           value: Sleeping space
         - dps_val: "5"

+ 3 - 3
custom_components/tuya_local/helpers/device_config.py

@@ -433,14 +433,14 @@ class TuyaDpsConfig:
             return []
         val = []
         for m in self._config["mapping"]:
-            if "value" in m:
+            if "value" in m and not m.get("hidden", False):
                 val.append(m["value"])
             # If there is mirroring without override, include mirrored values
             elif "value_mirror" in m:
                 r_dps = self._entity.find_dps(m["value_mirror"])
                 val = val + r_dps.values(device)
             for c in m.get("conditions", {}):
-                if "value" in c:
+                if "value" in c and not c.get("hidden", False):
                     val.append(c["value"])
                 elif "value_mirror" in c:
                     r_dps = self._entity.find_dps(c["value_mirror"])
@@ -451,7 +451,7 @@ class TuyaDpsConfig:
                 _LOGGER.debug("Considering conditional mappings")
                 c_val = []
                 for m2 in cond["mapping"]:
-                    if "value" in m2:
+                    if "value" in m2 and not m2.get("hidden", False):
                         c_val.append(m2["value"])
                     elif "value_mirror" in m:
                         r_dps = self._entity.find_dps(m["value_mirror"])

+ 15 - 0
tests/const.py

@@ -1598,3 +1598,18 @@ TOMPD63LW_SOCKET_PAYLOAD = {
     # "105": False,
     # "106": False,
 }
+
+GOLDAIR_GPDH340_PAYLOAD = {
+    "1": True,
+    "2": "2",
+    "4": 60,
+    "6": "2",
+    "11": 0,
+    "103": 20,
+    "104": 72,
+    "105": 40,
+    "106": False,
+    "107": True,
+    "108": False,
+    "109": False,
+}

+ 60 - 0
tests/devices/test_goldair_gpdh340_dehumidifier.py

@@ -0,0 +1,60 @@
+from ..const import GOLDAIR_GPDH340_PAYLOAD
+from ..helpers import assert_device_properties_set
+from ..mixins.switch import SwitchableTests
+from .base_device_tests import TuyaDeviceTestCase
+
+SWITCH_DP = "1"
+MODE_DP = "2"
+HUMIDITY_DP = "4"
+FAN_DP = "6"
+ERROR_DP = "11"
+CURRENTTEMP_DP = "103"
+CURRENTHUMID_DP = "104"
+MODEL_DP = "105"
+CHILDLOCK_DP = "106"
+DISPLAY_DP = "107"
+FILTERCLEAN_DP = "108"
+PUMP_DP = "109"
+
+
+class TestGPDH340Dehumidifier(SwitchableTests, TuyaDeviceTestCase):
+    __test__ = True
+
+    def setUp(self):
+        self.setUpForConfig(
+            "goldair_gpdh340_dehumidifier.yaml", GOLDAIR_GPDH340_PAYLOAD
+        )
+        self.subject = self.entities.get("humidifier")
+        self.setUpSwitchable(SWITCH_DP, self.subject)
+
+        self.mark_secondary(
+            [
+                "light_front_display",
+                "lock_child_lock",
+                "binary_sensor_tank",
+                "binary_sensor_fault",
+                "binary_sensor_filter_clean_required",
+            ]
+        )
+
+    def test_available_modes(self):
+        self.assertCountEqual(
+            self.subject.available_modes,
+            ["Sleeping space", "Living space", "Basement", "Continuous"],
+        )
+
+    def test_mode(self):
+        self.dps[MODE_DP] = "2"
+        self.assertEqual(self.subject.mode, "Custom")
+        self.dps[MODE_DP] = "4"
+        self.assertEqual(self.subject.mode, "Sleeping space")
+        self.dps[MODE_DP] = "5"
+        self.assertEqual(self.subject.mode, "Living space")
+        self.dps[MODE_DP] = "6"
+        self.assertEqual(self.subject.mode, "Basement")
+        self.dps[MODE_DP] = "7"
+        self.assertEqual(self.subject.mode, "Continuous")
+
+    async def test_async_set_mode(self):
+        async with assert_device_properties_set(self.subject._device, {MODE_DP: "6"}):
+            await self.subject.async_set_mode("Basement")