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) 
* Brightness only (white mode) 
* Colour only (colour mode) 
* Colour only (white mode) 
* Colour temp only (colour mode) 
* Colour temp only (white mode) 
* Colour + brightness (colour mode) 
* Colour + brightness (white mode) 
* Colour temp + brightness (colour mode) 
* Colour temp + brightness (white mode) 

* Fix code formatting
This commit is contained in:
BNolet 2023-03-28 06:20:54 -04:00 committed by GitHub
parent 96dae587a9
commit 6fbdcac323
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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.