Fix brightness support for Tuya dimmers that use the Light ("dj") category (#60385)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
alexanv1 2021-11-29 07:45:00 -08:00 committed by GitHub
parent f18fe342ac
commit 9aa33a3cf8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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