Skip to content
Snippets Groups Projects
Unverified Commit 6fbdcac3 authored by BNolet's avatar BNolet Committed by GitHub
Browse files

Fix setting color + brightness of Tuya lights (#88470)

* Check if changing TO a color mode

Changing brightness alone does not change work mode, but changing brightness with a color value will keep the light in white mode. 

By verifying the new state has color or not, rather than the existing state being in color work mode, the light will change to color correctly.

Tuya interprets HSV as including the brightness in the (v) value (which is generally what that's used for when setting HSV values). The brightness value given by Home Assistant is still used in this case.

* Fix brightness-only turning colour mode to white

This will take into account the case where brightness is the only parameter for both the case of colour mode and white mode.

Tests passed after this change:

* Brightness only (colour mode) :white_check_mark:
* Brightness only (white mode) :white_check_mark:
* Colour only (colour mode) :white_check_mark:
* Colour only (white mode) :white_check_mark:
* Colour temp only (colour mode) :white_check_mark:
* Colour temp only (white mode) :white_check_mark:
* Colour + brightness (colour mode) :white_check_mark:
* Colour + brightness (white mode) :white_check_mark:
* Colour temp + brightness (colour mode) :white_check_mark:
* Colour temp + brightness (white mode) :white_check_mark:

* Fix code formatting
parent 96dae587
No related branches found
No related tags found
No related merge requests found
......@@ -499,9 +499,14 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
),
},
]
elif self._color_data_type and (
if self._color_data_type and (
ATTR_HS_COLOR in kwargs
or (ATTR_BRIGHTNESS in kwargs and self.color_mode == ColorMode.HS)
or (
ATTR_BRIGHTNESS in kwargs
and self.color_mode == ColorMode.HS
and ATTR_COLOR_TEMP not in kwargs
)
):
if self._color_mode_dpcode:
commands += [
......@@ -542,11 +547,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
},
]
if (
ATTR_BRIGHTNESS in kwargs
and self.color_mode != ColorMode.HS
and self._brightness
):
elif ATTR_BRIGHTNESS in kwargs and self._brightness:
brightness = kwargs[ATTR_BRIGHTNESS]
# If there is a min/max value, the brightness is actually limited.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment