Quellcode durchsuchen

Swap order of scaling and inverting.

Inversion uses min and max from the config, so needs to be done on the device scaled value, not the HA scale as was previously done.
Jason Rumney vor 4 Jahren
Ursprung
Commit
1861d6de56
1 geänderte Dateien mit 10 neuen und 10 gelöschten Zeilen
  1. 10 10
      custom_components/tuya_local/helpers/device_config.py

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

@@ -522,16 +522,16 @@ class TuyaDpsConfig:
                 r_dps = self._entity.find_dps(mirror)
                 r_dps = self._entity.find_dps(mirror)
                 return r_dps.get_value(device)
                 return r_dps.get_value(device)
 
 
-            if scale != 1 and isinstance(result, (int, float)):
-                result = result / scale
-                replaced = True
-
             if invert:
             if invert:
                 r = self._config.get("range")
                 r = self._config.get("range")
                 if r and "min" in r and "max" in r:
                 if r and "min" in r and "max" in r:
                     result = -1 * result + r["min"] + r["max"]
                     result = -1 * result + r["min"] + r["max"]
                     replaced = True
                     replaced = True
 
 
+            if scale != 1 and isinstance(result, (int, float)):
+                result = result / scale
+                replaced = True
+
             if replaced:
             if replaced:
                 _LOGGER.debug(
                 _LOGGER.debug(
                     "%s: Mapped dps %s value from %s to %s",
                     "%s: Mapped dps %s value from %s to %s",
@@ -631,12 +631,6 @@ class TuyaDpsConfig:
                 r_dps = self._entity.find_dps(redirect)
                 r_dps = self._entity.find_dps(redirect)
                 return r_dps.get_values_to_set(device, value)
                 return r_dps.get_values_to_set(device, value)
 
 
-            if invert:
-                r = self._config.get("range")
-                if r and "min" in r and "max" in r:
-                    result = -1 * result + r["min"] + r["max"]
-                    replaced = True
-
             if scale != 1 and isinstance(result, (int, float)):
             if scale != 1 and isinstance(result, (int, float)):
                 _LOGGER.debug(f"Scaling {result} by {scale}")
                 _LOGGER.debug(f"Scaling {result} by {scale}")
                 result = result * scale
                 result = result * scale
@@ -645,6 +639,12 @@ class TuyaDpsConfig:
                     result = remap["dps_val"]
                     result = remap["dps_val"]
                 replaced = True
                 replaced = True
 
 
+            if invert:
+                r = self._config.get("range")
+                if r and "min" in r and "max" in r:
+                    result = -1 * result + r["min"] + r["max"]
+                    replaced = True
+
             if step and isinstance(result, (int, float)):
             if step and isinstance(result, (int, float)):
                 _LOGGER.debug(f"Stepping {result} to {step}")
                 _LOGGER.debug(f"Stepping {result} to {step}")
                 result = step * round(float(result) / step)
                 result = step * round(float(result) / step)