Просмотр исходного кода

fix(humidifier): properly handle step and range for discrete humidity

Previously humidity required range and step to be specified
regardless of whether it was an integer or discrete string
based control. Otherwise the defaults of 0-100 with steps of
1 was used.

Out of 17 configs with discrete humidity steps, only 2
were properly configured with both range and steps.
As well as being difficult to remember, it is also
cumbersome to code, as step needs to be specified on
every mapping.

Modified humidifier to calculate range and step from
the mapping values so they do not need to be explicitly
included.

Updated existing configs:

- dropped range and step from those that specified it
  to simplify the configs.
- for humidifiers that had a "continuous" setting,
  make it contiguous with the range at a consistent step
  spacing rather than 0 or 100.
Jason Rumney 17 часов назад
Родитель
Сommit
762f51bd35

+ 0 - 6
custom_components/tuya_local/devices/aerium_dh12w_dehumidifier.yaml

@@ -14,22 +14,16 @@ entities:
       - id: 3
         type: string
         name: humidity
-        range:
-          min: 40
-          max: 60
         mapping:
           - dps_val: "0"
             value: null
             hidden: true
           - dps_val: "40"
-            step: 10
             value: 40
           - dps_val: "50"
             value: 50
-            step: 10
           - dps_val: "60"
             value: 60
-            step: 10
       - id: 3
         type: string
         name: mode

+ 1 - 1
custom_components/tuya_local/devices/arida_eva_humidifier.yaml

@@ -15,7 +15,7 @@ entities:
         type: string
         mapping:
           - dps_val: cancel
-            value: 0
+            value: 25
           - dps_val: 30t
             value: 30
           - dps_val: 35t

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

@@ -16,9 +16,6 @@ entities:
       - id: 102
         type: string
         name: humidity
-        range:
-          min: 30
-          max: 75
         mapping:
           - dps_val: "30H"
             value: 30

+ 1 - 1
custom_components/tuya_local/devices/cleanair_607b_humidifier.yaml

@@ -15,7 +15,7 @@ entities:
         name: humidity
         mapping:
           - dps_val: "cancel"
-            value: 0
+            value: 35
           - dps_val: "40"
             value: 40
           - dps_val: "45"

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

@@ -28,9 +28,6 @@ entities:
       - id: 106
         type: string
         name: humidity
-        range:
-          min: 40
-          max: 60
         mapping:
           - dps_val: "40"
             value: 40

+ 1 - 4
custom_components/tuya_local/devices/inventor_atmospherexl_dehumidifier.yaml

@@ -17,12 +17,9 @@ entities:
       - id: 3
         type: string
         name: humidity
-        range:
-          min: 0
-          max: 80
         mapping:
           - dps_val: "CO"
-            value: 0
+            value: 35
           - dps_val: "40"
             value: 40
           - dps_val: "45"

+ 2 - 2
custom_components/tuya_local/devices/klarta_humea_grande_humidifier.yaml

@@ -14,8 +14,6 @@ entities:
         type: string
         name: humidity
         mapping:
-          - dps_val: "CO"
-            value: 100
           - dps_val: "40RH"
             value: 40
           - dps_val: "45RH"
@@ -32,6 +30,8 @@ entities:
             value: 70
           - dps_val: "75RH"
             value: 75
+          - dps_val: "CO"
+            value: 80
       - id: 14
         type: integer
         name: current_humidity

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

@@ -16,9 +16,6 @@ entities:
       - id: 101
         type: string
         name: humidity
-        range:
-          min: 40
-          max: 90
         mapping:
           - dps_val: "40"
             value: 40

+ 22 - 10
custom_components/tuya_local/devices/rztk_aqua_pro_wifi_humidifier.yaml

@@ -6,6 +6,7 @@ products:
 entities:
   - entity: humidifier
     class: humidifier
+    translation_only_key: extended
     dps:
       - id: 1
         name: switch
@@ -18,25 +19,36 @@ entities:
         type: string
         mapping:
           - dps_val: cancel
-            value: 0
-          - dps_val: 40
+            value: null
+            hidden: true
+          - dps_val: "40"
             value: 40
-          - dps_val: 45
+          - dps_val: "45"
             value: 45
-          - dps_val: 50
+          - dps_val: "50"
             value: 50
-          - dps_val: 55
+          - dps_val: "55"
             value: 55
-          - dps_val: 60
+          - dps_val: "60"
             value: 60
-          - dps_val: 65
+          - dps_val: "65"
             value: 65
-          - dps_val: 70
+          - dps_val: "70"
             value: 70
-          - dps_val: 75
+          - dps_val: "75"
             value: 75
-          - dps_val: 80
+          - dps_val: "80"
             value: 80
+      - id: 101
+        name: mode
+        type: string
+        mapping:
+          - dps_val: cancel
+            value: continuous
+          - dps_val: "60"
+            value: normal
+          - value: normal
+            hidden: true
   - entity: switch
     translation_key: uv_sterilization
     category: config

+ 0 - 13
custom_components/tuya_local/devices/wood_wdd90_dehumidifier.yaml

@@ -13,40 +13,27 @@ entities:
       - id: 3
         type: string
         name: humidity
-        range:
-          min: 35
-          max: 80
         mapping:
           - dps_val: "35"
             value: 35
-            step: 5
           - dps_val: "40"
             value: 40
-            step: 5
           - dps_val: "45"
             value: 45
-            step: 5
           - dps_val: "50"
             value: 50
-            step: 5
           - dps_val: "55"
             value: 55
-            step: 5
           - dps_val: "60"
             value: 60
-            step: 5
           - dps_val: "65"
             value: 65
-            step: 5
           - dps_val: "70"
             value: 70
-            step: 5
           - dps_val: "75"
             value: 75
-            step: 5
           - dps_val: "80"
             value: 80
-            step: 5
       - id: 6
         type: integer
         name: current_humidity

+ 0 - 7
custom_components/tuya_local/devices/woods_mrd25gw_dehumidifier.yaml

@@ -19,19 +19,12 @@ entities:
         mapping:
           - dps_val: "40"
             value: 40
-            step: 10
           - dps_val: "50"
             value: 50
-            step: 10
           - dps_val: "60"
             value: 60
-            step: 10
           - dps_val: "70"
             value: 70
-            step: 10
-        range:
-          min: 40
-          max: 70
       # Fan speed as mode (Low/High)
       - id: 4
         name: mode

+ 16 - 1
custom_components/tuya_local/humidifier.py

@@ -54,7 +54,18 @@ class TuyaLocalHumidifier(TuyaLocalEntity, HumidifierEntity):
         self._init_end(dps_map)
 
         if self._humidity_dp is not None:
-            self._attr_target_humidity_step = self._humidity_dp.step(device)
+            if self._humidity_dp.values(device):
+                n = self._humidity_dp.values(device).len()
+                minimum = self._humidity_dp.range(device)[0]
+                maximum = self._humidity_dp.range(device)[1]
+                step = (
+                    abs(maximum - minimum) / (n - 1)
+                    if n > 1
+                    else self._humidity_dp.step(device)
+                )
+            else:
+                step = self._humidity_dp.step(device)
+            self._attr_target_humidity_step = step
 
         self._support_flags = HumidifierEntityFeature(0)
         if self._mode_dp:
@@ -129,6 +140,8 @@ class TuyaLocalHumidifier(TuyaLocalEntity, HumidifierEntity):
         if self._humidity_dp is None:
             return None
         r = self._humidity_dp.range(self._device)
+        if r is None and self._humidity_dp.values(self._device):
+            return min(self._humidity_dp.values(self._device))
         return DEFAULT_MIN_HUMIDITY if r is None else r[0]
 
     @property
@@ -137,6 +150,8 @@ class TuyaLocalHumidifier(TuyaLocalEntity, HumidifierEntity):
         if self._humidity_dp is None:
             return None
         r = self._humidity_dp.range(self._device)
+        if r is None and self._humidity_dp.values(self._device):
+            return max(self._humidity_dp.values(self._device))
         return DEFAULT_MAX_HUMIDITY if r is None else r[1]
 
     async def async_set_humidity(self, humidity):