From 9aa33a3cf8071e04050ba8bd1694bd3db2bc66ba Mon Sep 17 00:00:00 2001 From: alexanv1 <44785744+alexanv1@users.noreply.github.com> Date: Mon, 29 Nov 2021 07:45:00 -0800 Subject: [PATCH] Fix brightness support for Tuya dimmers that use the Light ("dj") category (#60385) Co-authored-by: Franck Nijhof Co-authored-by: Franck Nijhof --- homeassistant/components/tuya/light.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/homeassistant/components/tuya/light.py b/homeassistant/components/tuya/light.py index 581cd85647b..16eda1cc324 100644 --- a/homeassistant/components/tuya/light.py +++ b/homeassistant/components/tuya/light.py @@ -330,6 +330,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity): _brightness_type: IntegerTypeData | None = None _color_data_dpcode: DPCode | None = None _color_data_type: ColorTypeData | None = None + _color_mode_dpcode: DPCode | None = None _color_temp_dpcode: DPCode | None = None _color_temp_type: IntegerTypeData | None = None @@ -361,6 +362,13 @@ class TuyaLightEntity(TuyaEntity, LightEntity): None, ) + # Determine color mode DPCode + if ( + description.color_mode is not None + and description.color_mode in device.function + ): + self._color_mode_dpcode = description.color_mode + # Determine DPCodes for color temperature if ( isinstance(description.color_temp, DPCode) @@ -451,10 +459,10 @@ class TuyaLightEntity(TuyaEntity, LightEntity): commands = [{"code": self.entity_description.key, "value": True}] if self._color_temp_type and ATTR_COLOR_TEMP in kwargs: - if color_mode_dpcode := self.entity_description.color_mode: + if self._color_mode_dpcode: commands += [ { - "code": color_mode_dpcode, + "code": self._color_mode_dpcode, "value": WorkMode.WHITE, }, ] @@ -476,10 +484,10 @@ class TuyaLightEntity(TuyaEntity, LightEntity): ATTR_HS_COLOR in kwargs or (ATTR_BRIGHTNESS in kwargs and self.color_mode == COLOR_MODE_HS) ): - if color_mode_dpcode := self.entity_description.color_mode: + if self._color_mode_dpcode: commands += [ { - "code": color_mode_dpcode, + "code": self._color_mode_dpcode, "value": WorkMode.COLOUR, }, ] @@ -651,9 +659,8 @@ class TuyaLightEntity(TuyaEntity, LightEntity): # We consider it to be in HS color mode, when work mode is anything # else than "white". if ( - self.entity_description.color_mode - and self.device.status.get(self.entity_description.color_mode) - != WorkMode.WHITE + self._color_mode_dpcode + and self.device.status.get(self._color_mode_dpcode) != WorkMode.WHITE ): return COLOR_MODE_HS if self._color_temp_dpcode: