Fix color temp selection when brightness changed in Tuya light (#58341)

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
Peter A. Bigot 2021-11-02 12:48:29 -05:00 committed by GitHub
parent 2b22d635d9
commit 4a2fb0e7ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -443,7 +443,29 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
"""Turn on or control the light."""
commands = [{"code": self.entity_description.key, "value": True}]
if self._color_data_type and (
if self._color_temp_type and ATTR_COLOR_TEMP in kwargs:
if color_mode_dpcode := self.entity_description.color_mode:
commands += [
{
"code": color_mode_dpcode,
"value": WorkMode.WHITE,
},
]
commands += [
{
"code": self._color_temp_dpcode,
"value": round(
self._color_temp_type.remap_value_from(
kwargs[ATTR_COLOR_TEMP],
self.min_mireds,
self.max_mireds,
reverse=True,
)
),
},
]
elif self._color_data_type and (
ATTR_HS_COLOR in kwargs
or (ATTR_BRIGHTNESS in kwargs and self.color_mode == COLOR_MODE_HS)
):
@ -486,29 +508,6 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
},
]
elif ATTR_COLOR_TEMP in kwargs and self._color_temp_type:
if color_mode_dpcode := self.entity_description.color_mode:
commands += [
{
"code": color_mode_dpcode,
"value": WorkMode.WHITE,
},
]
commands += [
{
"code": self._color_temp_dpcode,
"value": round(
self._color_temp_type.remap_value_from(
kwargs[ATTR_COLOR_TEMP],
self.min_mireds,
self.max_mireds,
reverse=True,
)
),
},
]
if (
ATTR_BRIGHTNESS in kwargs
and self.color_mode != COLOR_MODE_HS