Add support for light color modes (#47720)
* Add support for light color modes * Update tests * Update comments * Fix bugs, add tests * Suppress lint errors * Don't suppress brightness when state is ambiguous * Improve reproduce_state + add tests * Add comment * Change COLOR_MODE_* constants, rename COLOR_MODE_DIMMER to COLOR_MODE_BRIGHTNESS * Fix tests * Tweaks
This commit is contained in:
parent
333e6a215a
commit
5f2326fb57
8 changed files with 897 additions and 39 deletions
|
@ -1,4 +1,7 @@
|
|||
"""Test reproduce state for Light."""
|
||||
import pytest
|
||||
|
||||
from homeassistant.components import light
|
||||
from homeassistant.components.light.reproduce_state import DEPRECATION_WARNING
|
||||
from homeassistant.core import State
|
||||
|
||||
|
@ -15,6 +18,8 @@ VALID_HS_COLOR = {"hs_color": (345, 75)}
|
|||
VALID_KELVIN = {"kelvin": 4000}
|
||||
VALID_PROFILE = {"profile": "relax"}
|
||||
VALID_RGB_COLOR = {"rgb_color": (255, 63, 111)}
|
||||
VALID_RGBW_COLOR = {"rgbw_color": (255, 63, 111, 10)}
|
||||
VALID_RGBWW_COLOR = {"rgbww_color": (255, 63, 111, 10, 20)}
|
||||
VALID_XY_COLOR = {"xy_color": (0.59, 0.274)}
|
||||
|
||||
|
||||
|
@ -91,51 +96,51 @@ async def test_reproducing_states(hass, caplog):
|
|||
|
||||
expected_calls = []
|
||||
|
||||
expected_off = VALID_BRIGHTNESS
|
||||
expected_off = dict(VALID_BRIGHTNESS)
|
||||
expected_off["entity_id"] = "light.entity_off"
|
||||
expected_calls.append(expected_off)
|
||||
|
||||
expected_bright = VALID_WHITE_VALUE
|
||||
expected_bright = dict(VALID_WHITE_VALUE)
|
||||
expected_bright["entity_id"] = "light.entity_bright"
|
||||
expected_calls.append(expected_bright)
|
||||
|
||||
expected_white = VALID_FLASH
|
||||
expected_white = dict(VALID_FLASH)
|
||||
expected_white["entity_id"] = "light.entity_white"
|
||||
expected_calls.append(expected_white)
|
||||
|
||||
expected_flash = VALID_EFFECT
|
||||
expected_flash = dict(VALID_EFFECT)
|
||||
expected_flash["entity_id"] = "light.entity_flash"
|
||||
expected_calls.append(expected_flash)
|
||||
|
||||
expected_effect = VALID_TRANSITION
|
||||
expected_effect = dict(VALID_TRANSITION)
|
||||
expected_effect["entity_id"] = "light.entity_effect"
|
||||
expected_calls.append(expected_effect)
|
||||
|
||||
expected_trans = VALID_COLOR_NAME
|
||||
expected_trans = dict(VALID_COLOR_NAME)
|
||||
expected_trans["entity_id"] = "light.entity_trans"
|
||||
expected_calls.append(expected_trans)
|
||||
|
||||
expected_name = VALID_COLOR_TEMP
|
||||
expected_name = dict(VALID_COLOR_TEMP)
|
||||
expected_name["entity_id"] = "light.entity_name"
|
||||
expected_calls.append(expected_name)
|
||||
|
||||
expected_temp = VALID_HS_COLOR
|
||||
expected_temp = dict(VALID_HS_COLOR)
|
||||
expected_temp["entity_id"] = "light.entity_temp"
|
||||
expected_calls.append(expected_temp)
|
||||
|
||||
expected_hs = VALID_KELVIN
|
||||
expected_hs = dict(VALID_KELVIN)
|
||||
expected_hs["entity_id"] = "light.entity_hs"
|
||||
expected_calls.append(expected_hs)
|
||||
|
||||
expected_kelvin = VALID_PROFILE
|
||||
expected_kelvin = dict(VALID_PROFILE)
|
||||
expected_kelvin["entity_id"] = "light.entity_kelvin"
|
||||
expected_calls.append(expected_kelvin)
|
||||
|
||||
expected_profile = VALID_RGB_COLOR
|
||||
expected_profile = dict(VALID_RGB_COLOR)
|
||||
expected_profile["entity_id"] = "light.entity_profile"
|
||||
expected_calls.append(expected_profile)
|
||||
|
||||
expected_rgb = VALID_XY_COLOR
|
||||
expected_rgb = dict(VALID_XY_COLOR)
|
||||
expected_rgb["entity_id"] = "light.entity_rgb"
|
||||
expected_calls.append(expected_rgb)
|
||||
|
||||
|
@ -156,6 +161,59 @@ async def test_reproducing_states(hass, caplog):
|
|||
assert turn_off_calls[0].data == {"entity_id": "light.entity_xy"}
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"color_mode",
|
||||
(
|
||||
light.COLOR_MODE_COLOR_TEMP,
|
||||
light.COLOR_MODE_BRIGHTNESS,
|
||||
light.COLOR_MODE_HS,
|
||||
light.COLOR_MODE_ONOFF,
|
||||
light.COLOR_MODE_RGB,
|
||||
light.COLOR_MODE_RGBW,
|
||||
light.COLOR_MODE_RGBWW,
|
||||
light.COLOR_MODE_UNKNOWN,
|
||||
light.COLOR_MODE_XY,
|
||||
),
|
||||
)
|
||||
async def test_filter_color_modes(hass, caplog, color_mode):
|
||||
"""Test filtering of parameters according to color mode."""
|
||||
hass.states.async_set("light.entity", "off", {})
|
||||
all_colors = {
|
||||
**VALID_WHITE_VALUE,
|
||||
**VALID_COLOR_NAME,
|
||||
**VALID_COLOR_TEMP,
|
||||
**VALID_HS_COLOR,
|
||||
**VALID_KELVIN,
|
||||
**VALID_RGB_COLOR,
|
||||
**VALID_RGBW_COLOR,
|
||||
**VALID_RGBWW_COLOR,
|
||||
**VALID_XY_COLOR,
|
||||
}
|
||||
|
||||
turn_on_calls = async_mock_service(hass, "light", "turn_on")
|
||||
|
||||
await hass.helpers.state.async_reproduce_state(
|
||||
[State("light.entity", "on", {**all_colors, "color_mode": color_mode})]
|
||||
)
|
||||
|
||||
expected_map = {
|
||||
light.COLOR_MODE_COLOR_TEMP: VALID_COLOR_TEMP,
|
||||
light.COLOR_MODE_BRIGHTNESS: {},
|
||||
light.COLOR_MODE_HS: VALID_HS_COLOR,
|
||||
light.COLOR_MODE_ONOFF: {},
|
||||
light.COLOR_MODE_RGB: VALID_RGB_COLOR,
|
||||
light.COLOR_MODE_RGBW: VALID_RGBW_COLOR,
|
||||
light.COLOR_MODE_RGBWW: VALID_RGBWW_COLOR,
|
||||
light.COLOR_MODE_UNKNOWN: {**VALID_HS_COLOR, **VALID_WHITE_VALUE},
|
||||
light.COLOR_MODE_XY: VALID_XY_COLOR,
|
||||
}
|
||||
expected = expected_map[color_mode]
|
||||
|
||||
assert len(turn_on_calls) == 1
|
||||
assert turn_on_calls[0].domain == "light"
|
||||
assert dict(turn_on_calls[0].data) == {"entity_id": "light.entity", **expected}
|
||||
|
||||
|
||||
async def test_deprecation_warning(hass, caplog):
|
||||
"""Test deprecation warning."""
|
||||
hass.states.async_set("light.entity_off", "off", {})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue