1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add color_mode white (#51411)

* Add color_mode white

* Include brightness in white parameter

* Reformat

* Improve test coverage
This commit is contained in:
Erik Montnemery
2021-06-06 11:13:18 +02:00
committed by GitHub
parent 50001684aa
commit e560e623e9
4 changed files with 168 additions and 39 deletions

View File

@@ -1586,6 +1586,88 @@ async def test_light_service_call_color_conversion(hass, enable_custom_integrati
assert data == {"brightness": 128, "rgbww_color": (0, 75, 140, 255, 255)}
async def test_light_service_call_white_mode(hass, enable_custom_integrations):
"""Test color_mode white in service calls."""
platform = getattr(hass.components, "test.light")
platform.init(empty=True)
platform.ENTITIES.append(platform.MockLight("Test_white", STATE_ON))
entity0 = platform.ENTITIES[0]
entity0.supported_color_modes = {light.COLOR_MODE_HS, light.COLOR_MODE_WHITE}
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
await hass.async_block_till_done()
state = hass.states.get(entity0.entity_id)
assert state.attributes["supported_color_modes"] == [
light.COLOR_MODE_HS,
light.COLOR_MODE_WHITE,
]
await hass.services.async_call(
"light",
"turn_on",
{
"entity_id": [entity0.entity_id],
"brightness_pct": 100,
"hs_color": (240, 100),
},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"brightness": 255, "hs_color": (240.0, 100.0)}
entity0.calls = []
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity0.entity_id], "white": 50},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"white": 50}
entity0.calls = []
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity0.entity_id], "white": 0},
blocking=True,
)
_, data = entity0.last_call("turn_off")
assert data == {}
entity0.calls = []
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity0.entity_id], "brightness_pct": 100, "white": 50},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"white": 255}
entity0.calls = []
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity0.entity_id], "brightness": 100, "white": 0},
blocking=True,
)
_, data = entity0.last_call("turn_on")
assert data == {"white": 100}
entity0.calls = []
await hass.services.async_call(
"light",
"turn_on",
{"entity_id": [entity0.entity_id], "brightness_pct": 0, "white": 50},
blocking=True,
)
_, data = entity0.last_call("turn_off")
assert data == {}
async def test_light_state_color_conversion(hass, enable_custom_integrations):
"""Test color conversion in state updates."""
platform = getattr(hass.components, "test.light")