Explorar o código

fix (light): use the full lower range of light brightness

Tuya lights commonly have a range of 10-1000 for brightness, but due
to rounding error, 13 is the lowest that HA can set it to. When HA is
setting brightness 1, use the minimum rather than the standard HA range
calculation.

Issue #4060
Jason Rumney hai 7 meses
pai
achega
3aadb39a48
Modificáronse 1 ficheiros con 10 adicións e 2 borrados
  1. 10 2
      custom_components/tuya_local/light.py

+ 10 - 2
custom_components/tuya_local/light.py

@@ -289,7 +289,11 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
                 )
                 r = self._brightness_dps.range(self._device)
                 if r:
-                    bright = color_util.brightness_to_value(r, bright)
+                    # ensure full range is used
+                    if bright == 1 and r[0] != 0:
+                        bright = r[0]
+                    else:
+                        bright = color_util.brightness_to_value(r, bright)
 
                 settings = {
                     **settings,
@@ -448,7 +452,11 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
 
             r = self._brightness_dps.range(self._device)
             if r:
-                bright = color_util.brightness_to_value(r, bright)
+                # ensure full range is used
+                if bright == 1 and r[0] != 0:
+                    bright = r[0]
+                else:
+                    bright = color_util.brightness_to_value(r, bright)
 
             settings = {
                 **settings,