Răsfoiți Sursa

fix (device_config): redirect first when setting values.

If the current dps_val has a redirection, then use that first.
Mostly this is used for null mappings to redirect to an alternate dp,
which we want to work in both directions.
Previously I think this had to be in a condition block to work, but
it is more obvious to do it directly in the mapping in the null handling case.

Issue #3987
Jason Rumney 3 luni în urmă
părinte
comite
5845ac5386
1 a modificat fișierele cu 12 adăugiri și 0 ștergeri
  1. 12 0
      custom_components/tuya_local/helpers/device_config.py

+ 12 - 0
custom_components/tuya_local/helpers/device_config.py

@@ -932,6 +932,18 @@ class TuyaDpsConfig:
         if self.readonly:
             return dps_map
 
+        # Special case: if the current value has a redirect mapping,
+        # follow that.
+        current_value = device.get_property(self.id)
+        current_mapping = self._find_map_for_dps(current_value, device)
+        if current_mapping:
+            redirect = current_mapping.get("value_redirect")
+            if redirect:
+                return self._entity.find_dps(redirect).get_values_to_set(
+                    device,
+                    value,
+                )
+        # If no redirect, we need to check for mapped values in reverse
         mapping = self._find_map_for_value(value, device)
         scale = self.scale(device)
         mask = self.mask