Fix Tuya light color data wrapper (#160280)

This commit is contained in:
epenet
2026-01-05 10:27:57 +01:00
committed by GitHub
parent 6aaa57f660
commit 98ee0421b7
2 changed files with 18 additions and 5 deletions

View File

@@ -186,14 +186,14 @@ class _ColorDataWrapper(DPCodeJsonWrapper):
)
def _convert_value_to_raw_value(
self, device: CustomerDevice, value: tuple[tuple[float, float], float]
self, device: CustomerDevice, value: tuple[float, float, float]
) -> Any:
"""Convert a Home Assistant color/brightness pair back to a raw device value."""
color, brightness = value
"""Convert a Home Assistant tuple (H, S, V) back to a raw device value."""
hue, saturation, brightness = value
return json.dumps(
{
"h": round(self.h_type.remap_value_from(color[0])),
"s": round(self.s_type.remap_value_from(color[1])),
"h": round(self.h_type.remap_value_from(hue)),
"s": round(self.s_type.remap_value_from(saturation)),
"v": round(self.v_type.remap_value_from(brightness)),
}
)

View File

@@ -11,6 +11,7 @@ from tuya_sharing import CustomerDevice, Manager
from homeassistant.components.light import (
ATTR_BRIGHTNESS,
ATTR_HS_COLOR,
ATTR_WHITE,
DOMAIN as LIGHT_DOMAIN,
SERVICE_TURN_OFF,
@@ -91,6 +92,18 @@ async def test_platform_setup_and_discovery(
{"code": "bright_value_v2", "value": 592},
],
),
(
SERVICE_TURN_ON,
{
ATTR_BRIGHTNESS: 255,
ATTR_HS_COLOR: (10.1, 20.2),
},
[
{"code": "switch_led", "value": True},
{"code": "work_mode", "value": "colour"},
{"code": "colour_data_v2", "value": '{"h": 10, "s": 202, "v": 1000}'},
],
),
(
SERVICE_TURN_OFF,
{},