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

fix(light): add workaround for HA not respecting the minimum

As noted on PR #5123, when we have a very granular brightness,
color_util.brightness_to_value(range, brightness) does not stay in range,
eg with a range (1, 6), and a brightness of 20 (~8%), it returns 0.47 which
causes an error if we try to set it to the dp.
Jason Rumney 1 месяц назад
Родитель
Сommit
c33c67b2da
1 измененных файлов с 3 добавлено и 1 удалено
  1. 3 1
      custom_components/tuya_local/light.py

+ 3 - 1
custom_components/tuya_local/light.py

@@ -477,7 +477,9 @@ class TuyaLocalLight(TuyaLocalEntity, LightEntity):
                     bright = r[0]
                 else:
                     bright = color_util.brightness_to_value(r, bright)
-
+                    # workaround brightness_to_value not respecting the minimum
+                    if bright < r[0]:
+                        bright = r[0]
             _LOGGER.info("%s setting brightness to %d", self._config.config_id, bright)
             settings = {
                 **settings,