mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 21:27:38 +00:00
Support Tuya strip lights with correct values for saturation and brightness (#63812)
Co-authored-by: Franck Nijhof <git@frenck.dev>
This commit is contained in:
parent
2e97719650
commit
40d0a6e99e
@ -30,6 +30,28 @@ from .const import DOMAIN, TUYA_DISCOVERY_NEW, DPCode, WorkMode
|
|||||||
from .util import remap_value
|
from .util import remap_value
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class ColorTypeData:
|
||||||
|
"""Color Type Data."""
|
||||||
|
|
||||||
|
h_type: IntegerTypeData
|
||||||
|
s_type: IntegerTypeData
|
||||||
|
v_type: IntegerTypeData
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT_COLOR_TYPE_DATA = ColorTypeData(
|
||||||
|
h_type=IntegerTypeData(min=1, scale=0, max=360, step=1),
|
||||||
|
s_type=IntegerTypeData(min=1, scale=0, max=255, step=1),
|
||||||
|
v_type=IntegerTypeData(min=1, scale=0, max=255, step=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
DEFAULT_COLOR_TYPE_DATA_V2 = ColorTypeData(
|
||||||
|
h_type=IntegerTypeData(min=1, scale=0, max=360, step=1),
|
||||||
|
s_type=IntegerTypeData(min=1, scale=0, max=1000, step=1),
|
||||||
|
v_type=IntegerTypeData(min=1, scale=0, max=1000, step=1),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TuyaLightEntityDescription(LightEntityDescription):
|
class TuyaLightEntityDescription(LightEntityDescription):
|
||||||
"""Describe an Tuya light entity."""
|
"""Describe an Tuya light entity."""
|
||||||
@ -40,6 +62,7 @@ class TuyaLightEntityDescription(LightEntityDescription):
|
|||||||
color_data: DPCode | tuple[DPCode, ...] | None = None
|
color_data: DPCode | tuple[DPCode, ...] | None = None
|
||||||
color_mode: DPCode | None = None
|
color_mode: DPCode | None = None
|
||||||
color_temp: DPCode | tuple[DPCode, ...] | None = None
|
color_temp: DPCode | tuple[DPCode, ...] | None = None
|
||||||
|
default_color_type: ColorTypeData = DEFAULT_COLOR_TYPE_DATA
|
||||||
|
|
||||||
|
|
||||||
LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
|
LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
|
||||||
@ -63,6 +86,7 @@ LIGHTS: dict[str, tuple[TuyaLightEntityDescription, ...]] = {
|
|||||||
brightness=DPCode.BRIGHT_VALUE,
|
brightness=DPCode.BRIGHT_VALUE,
|
||||||
color_temp=DPCode.TEMP_VALUE,
|
color_temp=DPCode.TEMP_VALUE,
|
||||||
color_data=DPCode.COLOUR_DATA,
|
color_data=DPCode.COLOUR_DATA,
|
||||||
|
default_color_type=DEFAULT_COLOR_TYPE_DATA_V2,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
# Light
|
# Light
|
||||||
@ -242,28 +266,6 @@ LIGHTS["cz"] = LIGHTS["kg"]
|
|||||||
LIGHTS["pc"] = LIGHTS["kg"]
|
LIGHTS["pc"] = LIGHTS["kg"]
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class ColorTypeData:
|
|
||||||
"""Color Type Data."""
|
|
||||||
|
|
||||||
h_type: IntegerTypeData
|
|
||||||
s_type: IntegerTypeData
|
|
||||||
v_type: IntegerTypeData
|
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_COLOR_TYPE_DATA = ColorTypeData(
|
|
||||||
h_type=IntegerTypeData(min=1, scale=0, max=360, step=1),
|
|
||||||
s_type=IntegerTypeData(min=1, scale=0, max=255, step=1),
|
|
||||||
v_type=IntegerTypeData(min=1, scale=0, max=255, step=1),
|
|
||||||
)
|
|
||||||
|
|
||||||
DEFAULT_COLOR_TYPE_DATA_V2 = ColorTypeData(
|
|
||||||
h_type=IntegerTypeData(min=1, scale=0, max=360, step=1),
|
|
||||||
s_type=IntegerTypeData(min=1, scale=0, max=1000, step=1),
|
|
||||||
v_type=IntegerTypeData(min=1, scale=0, max=1000, step=1),
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class ColorData:
|
class ColorData:
|
||||||
"""Color Data."""
|
"""Color Data."""
|
||||||
@ -440,7 +442,7 @@ class TuyaLightEntity(TuyaEntity, LightEntity):
|
|||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
# If no type is found, use a default one
|
# If no type is found, use a default one
|
||||||
self._color_data_type = DEFAULT_COLOR_TYPE_DATA
|
self._color_data_type = self.entity_description.default_color_type
|
||||||
if self._color_data_dpcode == DPCode.COLOUR_DATA_V2 or (
|
if self._color_data_dpcode == DPCode.COLOUR_DATA_V2 or (
|
||||||
self._brightness_type and self._brightness_type.max > 255
|
self._brightness_type and self._brightness_type.max > 255
|
||||||
):
|
):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user