Browse Source

Don't try to invert non-numeric values.

Issue #241

Sometimes the value coming back from the device is None (for example many
lights do not return color_temp if they are not in color mode, but HA tries
to read the color_temp in various places if the light says it supports it).
In these cases, None should be returned from get_value(), but if the attribute
is configured to be inverted, an exception was thrown instead.
Jason Rumney 3 years ago
parent
commit
8e082ff903
1 changed files with 1 additions and 1 deletions
  1. 1 1
      custom_components/tuya_local/helpers/device_config.py

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

@@ -555,7 +555,7 @@ 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 invert:
+            if invert and isinstance(result, (int, float)):
                 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"]