Correct conversion of RGB and XY colors to RGBW (#49802)

pull/49807/head
Erik Montnemery 2021-04-28 10:12:20 +02:00 committed by GitHub
parent d6c01cc0e6
commit d7247c2ace
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 2 deletions

View File

@ -331,7 +331,7 @@ async def async_setup(hass, config): # noqa: C901
elif ATTR_RGB_COLOR in params and COLOR_MODE_RGB not in supported_color_modes:
rgb_color = params.pop(ATTR_RGB_COLOR)
if COLOR_MODE_RGBW in supported_color_modes:
params[ATTR_RGBW_COLOR] = (*rgb_color, 0)
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
if COLOR_MODE_RGBWW in supported_color_modes:
params[ATTR_RGBWW_COLOR] = (*rgb_color, 0, 0)
elif COLOR_MODE_HS in supported_color_modes:
@ -345,7 +345,8 @@ async def async_setup(hass, config): # noqa: C901
elif COLOR_MODE_RGB in supported_color_modes:
params[ATTR_RGB_COLOR] = color_util.color_xy_to_RGB(*xy_color)
elif COLOR_MODE_RGBW in supported_color_modes:
params[ATTR_RGBW_COLOR] = (*color_util.color_xy_to_RGB(*xy_color), 0)
rgb_color = color_util.color_xy_to_RGB(*xy_color)
params[ATTR_RGBW_COLOR] = color_util.color_rgb_to_rgbw(*rgb_color)
elif COLOR_MODE_RGBWW in supported_color_modes:
params[ATTR_RGBWW_COLOR] = (
*color_util.color_xy_to_RGB(*xy_color),

View File

@ -1367,6 +1367,39 @@ async def test_light_service_call_color_conversion(hass):
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (128, 0, 0, 0, 0)}
await hass.services.async_call(
"light",
"turn_on",
{
"entity_id": [
entity0.entity_id,
entity1.entity_id,
entity2.entity_id,
entity3.entity_id,
entity4.entity_id,
entity5.entity_id,
entity6.entity_id,
],
"brightness_pct": 50,
"rgb_color": (255, 255, 255),
},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"brightness": 128, "hs_color": (0.0, 0.0)}
_, data = entity1.last_call("turn_on")
assert data == {"brightness": 128, "rgb_color": (255, 255, 255)}
_, data = entity2.last_call("turn_on")
assert data == {"brightness": 128, "xy_color": (0.323, 0.329)}
_, data = entity3.last_call("turn_on")
assert data == {"brightness": 128, "rgb_color": (255, 255, 255)}
_, data = entity4.last_call("turn_on")
assert data == {"brightness": 128, "hs_color": (0.0, 0.0)}
_, data = entity5.last_call("turn_on")
assert data == {"brightness": 128, "rgbw_color": (0, 0, 0, 255)}
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (255, 255, 255, 0, 0)}
await hass.services.async_call(
"light",
"turn_on",
@ -1400,6 +1433,39 @@ async def test_light_service_call_color_conversion(hass):
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (0, 255, 22, 0, 0)}
await hass.services.async_call(
"light",
"turn_on",
{
"entity_id": [
entity0.entity_id,
entity1.entity_id,
entity2.entity_id,
entity3.entity_id,
entity4.entity_id,
entity5.entity_id,
entity6.entity_id,
],
"brightness_pct": 50,
"xy_color": (0.323, 0.329),
},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"brightness": 128, "hs_color": (0.0, 0.392)}
_, data = entity1.last_call("turn_on")
assert data == {"brightness": 128, "rgb_color": (255, 254, 254)}
_, data = entity2.last_call("turn_on")
assert data == {"brightness": 128, "xy_color": (0.323, 0.329)}
_, data = entity3.last_call("turn_on")
assert data == {"brightness": 128, "xy_color": (0.323, 0.329)}
_, data = entity4.last_call("turn_on")
assert data == {"brightness": 128, "hs_color": (0.0, 0.392)}
_, data = entity5.last_call("turn_on")
assert data == {"brightness": 128, "rgbw_color": (1, 0, 0, 255)}
_, data = entity6.last_call("turn_on")
assert data == {"brightness": 128, "rgbww_color": (255, 254, 254, 0, 0)}
async def test_light_state_color_conversion(hass):
"""Test color conversion in state updates."""