mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Update light turn_on schema to coerce colors to tuple before asserting sequence type (#58670)
* Make color_name_to_rgb return a tuple * Tweak * Tweak * Update test * Tweak test
This commit is contained in:
@@ -18,6 +18,7 @@ from homeassistant.const import (
|
||||
)
|
||||
from homeassistant.exceptions import Unauthorized
|
||||
from homeassistant.setup import async_setup_component
|
||||
import homeassistant.util.color as color_util
|
||||
|
||||
from tests.common import async_mock_service
|
||||
|
||||
@@ -1724,6 +1725,83 @@ async def test_light_service_call_color_conversion(hass, enable_custom_integrati
|
||||
assert data == {"brightness": 128, "rgbww_color": (255, 255, 255, 255, 255)}
|
||||
|
||||
|
||||
async def test_light_service_call_color_conversion_named_tuple(
|
||||
hass, enable_custom_integrations
|
||||
):
|
||||
"""Test a named tuple (RGBColor) is handled correctly."""
|
||||
platform = getattr(hass.components, "test.light")
|
||||
platform.init(empty=True)
|
||||
|
||||
platform.ENTITIES.append(platform.MockLight("Test_hs", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_rgb", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_xy", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_all", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_legacy", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_rgbw", STATE_ON))
|
||||
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
|
||||
|
||||
entity0 = platform.ENTITIES[0]
|
||||
entity0.supported_color_modes = {light.COLOR_MODE_HS}
|
||||
|
||||
entity1 = platform.ENTITIES[1]
|
||||
entity1.supported_color_modes = {light.COLOR_MODE_RGB}
|
||||
|
||||
entity2 = platform.ENTITIES[2]
|
||||
entity2.supported_color_modes = {light.COLOR_MODE_XY}
|
||||
|
||||
entity3 = platform.ENTITIES[3]
|
||||
entity3.supported_color_modes = {
|
||||
light.COLOR_MODE_HS,
|
||||
light.COLOR_MODE_RGB,
|
||||
light.COLOR_MODE_XY,
|
||||
}
|
||||
|
||||
entity4 = platform.ENTITIES[4]
|
||||
entity4.supported_features = light.SUPPORT_COLOR
|
||||
|
||||
entity5 = platform.ENTITIES[5]
|
||||
entity5.supported_color_modes = {light.COLOR_MODE_RGBW}
|
||||
|
||||
entity6 = platform.ENTITIES[6]
|
||||
entity6.supported_color_modes = {light.COLOR_MODE_RGBWW}
|
||||
|
||||
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
||||
await hass.async_block_till_done()
|
||||
|
||||
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": 25,
|
||||
"rgb_color": color_util.RGBColor(128, 0, 0),
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
_, data = entity0.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "hs_color": (0.0, 100.0)}
|
||||
_, data = entity1.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "rgb_color": (128, 0, 0)}
|
||||
_, data = entity2.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "xy_color": (0.701, 0.299)}
|
||||
_, data = entity3.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "rgb_color": (128, 0, 0)}
|
||||
_, data = entity4.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "hs_color": (0.0, 100.0)}
|
||||
_, data = entity5.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "rgbw_color": (128, 0, 0, 0)}
|
||||
_, data = entity6.last_call("turn_on")
|
||||
assert data == {"brightness": 64, "rgbww_color": (128, 0, 0, 0, 0)}
|
||||
|
||||
|
||||
async def test_light_service_call_color_temp_emulation(
|
||||
hass, enable_custom_integrations
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user