|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
"""The tests for the Light component."""
|
|
|
|
|
|
|
|
|
|
from unittest.mock import MagicMock, mock_open, patch
|
|
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
@ -23,6 +22,7 @@ from homeassistant.setup import async_setup_component
|
|
|
|
|
import homeassistant.util.color as color_util
|
|
|
|
|
|
|
|
|
|
from tests.common import MockEntityPlatform, MockUser, async_mock_service
|
|
|
|
|
from tests.fixtures.pytest.light import MockLight, SetupLightPlatformCallable
|
|
|
|
|
|
|
|
|
|
orig_Profiles = light.Profiles
|
|
|
|
|
|
|
|
|
@ -108,18 +108,20 @@ async def test_methods(hass: HomeAssistant) -> None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_services(
|
|
|
|
|
hass: HomeAssistant, mock_light_profiles, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_light_profiles,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test the provided services."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
platform.init()
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
ent1, ent2, ent3 = platform.ENTITIES
|
|
|
|
|
ent1, ent2, ent3 = mock_light_entities
|
|
|
|
|
ent1.supported_color_modes = [light.ColorMode.HS]
|
|
|
|
|
ent3.supported_color_modes = [light.ColorMode.HS]
|
|
|
|
|
ent1.supported_features = light.LightEntityFeature.TRANSITION
|
|
|
|
@ -509,11 +511,11 @@ async def test_light_profiles(
|
|
|
|
|
profile_name,
|
|
|
|
|
expected_data,
|
|
|
|
|
last_call,
|
|
|
|
|
enable_custom_integrations: None,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test light profiles."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
profile_mock_data = {
|
|
|
|
|
"test": (0.4, 0.6, 100, 0),
|
|
|
|
@ -533,7 +535,7 @@ async def test_light_profiles(
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
ent1, _, _ = platform.ENTITIES
|
|
|
|
|
ent1, _, _ = mock_light_entities
|
|
|
|
|
ent1.supported_color_modes = [light.ColorMode.HS]
|
|
|
|
|
ent1.supported_features = light.LightEntityFeature.TRANSITION
|
|
|
|
|
|
|
|
|
@ -556,11 +558,13 @@ async def test_light_profiles(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_default_profiles_group(
|
|
|
|
|
hass: HomeAssistant, mock_light_profiles, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_light_profiles,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test default turn-on light profile for all lights."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
@ -570,7 +574,7 @@ async def test_default_profiles_group(
|
|
|
|
|
profile = light.Profile("group.all_lights.default", 0.4, 0.6, 99, 2)
|
|
|
|
|
mock_light_profiles[profile.name] = profile
|
|
|
|
|
|
|
|
|
|
ent, _, _ = platform.ENTITIES
|
|
|
|
|
ent, _, _ = mock_light_entities
|
|
|
|
|
ent.supported_color_modes = [light.ColorMode.HS]
|
|
|
|
|
ent.supported_features = light.LightEntityFeature.TRANSITION
|
|
|
|
|
await hass.services.async_call(
|
|
|
|
@ -780,13 +784,13 @@ async def test_default_profiles_light(
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_light_profiles,
|
|
|
|
|
extra_call_params,
|
|
|
|
|
enable_custom_integrations: None,
|
|
|
|
|
expected_params_state_was_off,
|
|
|
|
|
expected_params_state_was_on,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test default turn-on light profile for a specific light."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
@ -798,7 +802,7 @@ async def test_default_profiles_light(
|
|
|
|
|
profile = light.Profile("light.ceiling_2.default", 0.6, 0.6, 100, 3)
|
|
|
|
|
mock_light_profiles[profile.name] = profile
|
|
|
|
|
|
|
|
|
|
dev = next(filter(lambda x: x.entity_id == "light.ceiling_2", platform.ENTITIES))
|
|
|
|
|
dev = next(filter(lambda x: x.entity_id == "light.ceiling_2", mock_light_entities))
|
|
|
|
|
dev.supported_color_modes = {
|
|
|
|
|
light.ColorMode.COLOR_TEMP,
|
|
|
|
|
light.ColorMode.HS,
|
|
|
|
@ -850,11 +854,13 @@ async def test_default_profiles_light(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_context(
|
|
|
|
|
hass: HomeAssistant, hass_admin_user: MockUser, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_admin_user: MockUser,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test that light context works."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
@ -876,11 +882,13 @@ async def test_light_context(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_turn_on_auth(
|
|
|
|
|
hass: HomeAssistant, hass_read_only_user: MockUser, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
hass_read_only_user: MockUser,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test that light context works."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
@ -900,20 +908,23 @@ async def test_light_turn_on_auth(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_brightness_step(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test that light context works."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_0", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_1", STATE_ON))
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_0", STATE_ON),
|
|
|
|
|
MockLight("Test_1", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_features = light.SUPPORT_BRIGHTNESS
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity0.supported_color_modes = None
|
|
|
|
|
entity0.color_mode = None
|
|
|
|
|
entity0.brightness = 100
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_features = light.SUPPORT_BRIGHTNESS
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity1.supported_color_modes = None
|
|
|
|
@ -970,12 +981,15 @@ async def test_light_brightness_step(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_brightness_pct_conversion(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
enable_custom_integrations: None,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test that light brightness percent conversion."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init()
|
|
|
|
|
entity = platform.ENTITIES[0]
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
entity = mock_light_entities[0]
|
|
|
|
|
entity.supported_features = light.SUPPORT_BRIGHTNESS
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity.supported_color_modes = None
|
|
|
|
@ -1130,39 +1144,38 @@ invalid_no_brightness_no_color_no_transition,,,
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize("light_state", [STATE_ON, STATE_OFF])
|
|
|
|
|
async def test_light_backwards_compatibility_supported_color_modes(
|
|
|
|
|
hass: HomeAssistant, light_state, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, light_state, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test supported_color_modes if not implemented by the entity."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_0", light_state),
|
|
|
|
|
MockLight("Test_1", light_state),
|
|
|
|
|
MockLight("Test_2", light_state),
|
|
|
|
|
MockLight("Test_3", light_state),
|
|
|
|
|
MockLight("Test_4", light_state),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_0", light_state))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_1", light_state))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_2", light_state))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_3", light_state))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_4", light_state))
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_features = light.SUPPORT_BRIGHTNESS
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity1.supported_color_modes = None
|
|
|
|
|
entity1.color_mode = None
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity2.supported_color_modes = None
|
|
|
|
|
entity2.color_mode = None
|
|
|
|
|
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity3.supported_color_modes = None
|
|
|
|
|
entity3.color_mode = None
|
|
|
|
|
|
|
|
|
|
entity4 = platform.ENTITIES[4]
|
|
|
|
|
entity4 = entities[4]
|
|
|
|
|
entity4.supported_features = (
|
|
|
|
|
light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP
|
|
|
|
|
)
|
|
|
|
@ -1170,6 +1183,8 @@ async def test_light_backwards_compatibility_supported_color_modes(
|
|
|
|
|
entity4.supported_color_modes = None
|
|
|
|
|
entity4.color_mode = None
|
|
|
|
|
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
@ -1213,42 +1228,41 @@ async def test_light_backwards_compatibility_supported_color_modes(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_backwards_compatibility_color_mode(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color_mode if not implemented by the entity."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_0", STATE_ON),
|
|
|
|
|
MockLight("Test_1", STATE_ON),
|
|
|
|
|
MockLight("Test_2", STATE_ON),
|
|
|
|
|
MockLight("Test_3", STATE_ON),
|
|
|
|
|
MockLight("Test_4", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_0", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_1", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_2", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_3", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_4", STATE_ON))
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_features = light.SUPPORT_BRIGHTNESS
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity1.supported_color_modes = None
|
|
|
|
|
entity1.color_mode = None
|
|
|
|
|
entity1.brightness = 100
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR_TEMP
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity2.supported_color_modes = None
|
|
|
|
|
entity2.color_mode = None
|
|
|
|
|
entity2.color_temp_kelvin = 10000
|
|
|
|
|
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.supported_features = light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity3.supported_color_modes = None
|
|
|
|
|
entity3.color_mode = None
|
|
|
|
|
entity3.hs_color = (240, 100)
|
|
|
|
|
|
|
|
|
|
entity4 = platform.ENTITIES[4]
|
|
|
|
|
entity4 = entities[4]
|
|
|
|
|
entity4.supported_features = (
|
|
|
|
|
light.SUPPORT_BRIGHTNESS | light.SUPPORT_COLOR | light.SUPPORT_COLOR_TEMP
|
|
|
|
|
)
|
|
|
|
@ -1258,6 +1272,8 @@ async def test_light_backwards_compatibility_color_mode(
|
|
|
|
|
entity4.hs_color = (240, 100)
|
|
|
|
|
entity4.color_temp_kelvin = 10000
|
|
|
|
|
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
@ -1290,17 +1306,14 @@ async def test_light_backwards_compatibility_color_mode(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_rgbw(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test rgbw functionality in service calls."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbw", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = MockLight("Test_rgbw", STATE_ON)
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.RGBW}
|
|
|
|
|
|
|
|
|
|
setup_light_platform([entity0])
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
@ -1323,24 +1336,24 @@ async def test_light_service_call_rgbw(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_state_off(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test rgbw color conversion in state updates."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_onoff", STATE_OFF),
|
|
|
|
|
MockLight("Test_brightness", STATE_OFF),
|
|
|
|
|
MockLight("Test_ct", STATE_OFF),
|
|
|
|
|
MockLight("Test_rgbw", STATE_OFF),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_onoff", STATE_OFF))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_brightness", STATE_OFF))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_ct", STATE_OFF))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbw", STATE_OFF))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.ONOFF}
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.BRIGHTNESS}
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_color_modes = {light.ColorMode.COLOR_TEMP}
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.supported_color_modes = {light.ColorMode.RGBW}
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
@ -1396,15 +1409,12 @@ async def test_light_state_off(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_state_rgbw(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test rgbw color conversion in state updates."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entity0 = MockLight("Test_rgbw", STATE_ON)
|
|
|
|
|
setup_light_platform([entity0])
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbw", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0.brightness = 255
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.RGBW}
|
|
|
|
|
entity0.color_mode = light.ColorMode.RGBW
|
|
|
|
@ -1432,15 +1442,12 @@ async def test_light_state_rgbw(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_state_rgbww(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test rgbww color conversion in state updates."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entity0 = MockLight("Test_rgbww", STATE_ON)
|
|
|
|
|
setup_light_platform([entity0])
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.RGBWW}
|
|
|
|
|
entity0.color_mode = light.ColorMode.RGBWW
|
|
|
|
|
entity0.hs_color = "Invalid" # Should be ignored
|
|
|
|
@ -1468,50 +1475,50 @@ async def test_light_state_rgbww(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_color_conversion(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color conversion in service calls."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_hs", STATE_ON),
|
|
|
|
|
MockLight("Test_rgb", STATE_ON),
|
|
|
|
|
MockLight("Test_xy", STATE_ON),
|
|
|
|
|
MockLight("Test_all", STATE_ON),
|
|
|
|
|
MockLight("Test_legacy", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbw", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbww", STATE_ON),
|
|
|
|
|
MockLight("Test_temperature", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_temperature", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.HS}
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.RGB}
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_color_modes = {light.ColorMode.XY}
|
|
|
|
|
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.supported_color_modes = {
|
|
|
|
|
light.ColorMode.HS,
|
|
|
|
|
light.ColorMode.RGB,
|
|
|
|
|
light.ColorMode.XY,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity4 = platform.ENTITIES[4]
|
|
|
|
|
entity4 = entities[4]
|
|
|
|
|
entity4.supported_features = light.SUPPORT_COLOR
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity4.supported_color_modes = None
|
|
|
|
|
entity4.color_mode = None
|
|
|
|
|
|
|
|
|
|
entity5 = platform.ENTITIES[5]
|
|
|
|
|
entity5 = entities[5]
|
|
|
|
|
entity5.supported_color_modes = {light.ColorMode.RGBW}
|
|
|
|
|
|
|
|
|
|
entity6 = platform.ENTITIES[6]
|
|
|
|
|
entity6 = entities[6]
|
|
|
|
|
entity6.supported_color_modes = {light.ColorMode.RGBWW}
|
|
|
|
|
|
|
|
|
|
entity7 = platform.ENTITIES[7]
|
|
|
|
|
entity7 = entities[7]
|
|
|
|
|
entity7.supported_color_modes = {light.ColorMode.COLOR_TEMP}
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
@ -1913,46 +1920,46 @@ async def test_light_service_call_color_conversion(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_color_conversion_named_tuple(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test a named tuple (RGBColor) is handled correctly."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_hs", STATE_ON),
|
|
|
|
|
MockLight("Test_rgb", STATE_ON),
|
|
|
|
|
MockLight("Test_xy", STATE_ON),
|
|
|
|
|
MockLight("Test_all", STATE_ON),
|
|
|
|
|
MockLight("Test_legacy", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbw", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbww", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
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 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.HS}
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.RGB}
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_color_modes = {light.ColorMode.XY}
|
|
|
|
|
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.supported_color_modes = {
|
|
|
|
|
light.ColorMode.HS,
|
|
|
|
|
light.ColorMode.RGB,
|
|
|
|
|
light.ColorMode.XY,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity4 = platform.ENTITIES[4]
|
|
|
|
|
entity4 = entities[4]
|
|
|
|
|
entity4.supported_features = light.SUPPORT_COLOR
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
|
entity4.supported_color_modes = None
|
|
|
|
|
entity4.color_mode = None
|
|
|
|
|
|
|
|
|
|
entity5 = platform.ENTITIES[5]
|
|
|
|
|
entity5 = entities[5]
|
|
|
|
|
entity5.supported_color_modes = {light.ColorMode.RGBW}
|
|
|
|
|
|
|
|
|
|
entity6 = platform.ENTITIES[6]
|
|
|
|
|
entity6 = entities[6]
|
|
|
|
|
entity6.supported_color_modes = {light.ColorMode.RGBWW}
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
@ -1993,23 +2000,23 @@ async def test_light_service_call_color_conversion_named_tuple(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_color_temp_emulation(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color conversion in service calls."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_hs_ct", STATE_ON),
|
|
|
|
|
MockLight("Test_hs", STATE_ON),
|
|
|
|
|
MockLight("Test_hs_white", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_hs_ct", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_hs", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_hs_white", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.COLOR_TEMP, light.ColorMode.HS}
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.HS}
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_color_modes = {light.ColorMode.HS, light.ColorMode.WHITE}
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
@ -2053,22 +2060,22 @@ async def test_light_service_call_color_temp_emulation(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_color_temp_conversion(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color temp conversion in service calls."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_rgbww_ct", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbww", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww_ct", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {
|
|
|
|
|
light.ColorMode.COLOR_TEMP,
|
|
|
|
|
light.ColorMode.RGBWW,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.RGBWW}
|
|
|
|
|
assert entity1.min_mireds == 153
|
|
|
|
|
assert entity1.max_mireds == 500
|
|
|
|
@ -2186,16 +2193,16 @@ async def test_light_service_call_color_temp_conversion(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_mired_color_temp_conversion(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color temp conversion from K to legacy mired."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_rgbww_ct", STATE_ON),
|
|
|
|
|
MockLight("Test_rgbww", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww_ct", STATE_ON))
|
|
|
|
|
platform.ENTITIES.append(platform.MockLight("Test_rgbww", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {
|
|
|
|
|
light.ColorMode.COLOR_TEMP,
|
|
|
|
|
}
|
|
|
|
@ -2234,15 +2241,12 @@ async def test_light_mired_color_temp_conversion(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_service_call_white_mode(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""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 = MockLight("Test_white", STATE_ON)
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.HS, light.ColorMode.WHITE}
|
|
|
|
|
setup_light_platform([entity0])
|
|
|
|
|
|
|
|
|
|
assert await async_setup_component(hass, "light", {"light": {"platform": "test"}})
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
@ -2338,39 +2342,39 @@ async def test_light_service_call_white_mode(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_light_state_color_conversion(
|
|
|
|
|
hass: HomeAssistant, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant, setup_light_platform: SetupLightPlatformCallable
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test color conversion in state updates."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
platform.init(empty=True)
|
|
|
|
|
entities = [
|
|
|
|
|
MockLight("Test_hs", STATE_ON),
|
|
|
|
|
MockLight("Test_rgb", STATE_ON),
|
|
|
|
|
MockLight("Test_xy", STATE_ON),
|
|
|
|
|
MockLight("Test_legacy", STATE_ON),
|
|
|
|
|
]
|
|
|
|
|
setup_light_platform(entities)
|
|
|
|
|
|
|
|
|
|
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_legacy", STATE_ON))
|
|
|
|
|
|
|
|
|
|
entity0 = platform.ENTITIES[0]
|
|
|
|
|
entity0 = entities[0]
|
|
|
|
|
entity0.supported_color_modes = {light.ColorMode.HS}
|
|
|
|
|
entity0.color_mode = light.ColorMode.HS
|
|
|
|
|
entity0.hs_color = (240, 100)
|
|
|
|
|
entity0.rgb_color = "Invalid" # Should be ignored
|
|
|
|
|
entity0.xy_color = "Invalid" # Should be ignored
|
|
|
|
|
|
|
|
|
|
entity1 = platform.ENTITIES[1]
|
|
|
|
|
entity1 = entities[1]
|
|
|
|
|
entity1.supported_color_modes = {light.ColorMode.RGB}
|
|
|
|
|
entity1.color_mode = light.ColorMode.RGB
|
|
|
|
|
entity1.hs_color = "Invalid" # Should be ignored
|
|
|
|
|
entity1.rgb_color = (128, 0, 0)
|
|
|
|
|
entity1.xy_color = "Invalid" # Should be ignored
|
|
|
|
|
|
|
|
|
|
entity2 = platform.ENTITIES[2]
|
|
|
|
|
entity2 = entities[2]
|
|
|
|
|
entity2.supported_color_modes = {light.ColorMode.XY}
|
|
|
|
|
entity2.color_mode = light.ColorMode.XY
|
|
|
|
|
entity2.hs_color = "Invalid" # Should be ignored
|
|
|
|
|
entity2.rgb_color = "Invalid" # Should be ignored
|
|
|
|
|
entity2.xy_color = (0.1, 0.8)
|
|
|
|
|
|
|
|
|
|
entity3 = platform.ENTITIES[3]
|
|
|
|
|
entity3 = entities[3]
|
|
|
|
|
entity3.hs_color = (240, 100)
|
|
|
|
|
entity3.supported_features = light.SUPPORT_COLOR
|
|
|
|
|
# Set color modes to none to trigger backwards compatibility in LightEntity
|
|
|
|
@ -2406,18 +2410,20 @@ async def test_light_state_color_conversion(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def test_services_filter_parameters(
|
|
|
|
|
hass: HomeAssistant, mock_light_profiles, enable_custom_integrations: None
|
|
|
|
|
hass: HomeAssistant,
|
|
|
|
|
mock_light_profiles,
|
|
|
|
|
setup_light_platform: SetupLightPlatformCallable,
|
|
|
|
|
mock_light_entities: list[MockLight],
|
|
|
|
|
) -> None:
|
|
|
|
|
"""Test turn_on and turn_off filters unsupported parameters."""
|
|
|
|
|
platform = getattr(hass.components, "test.light")
|
|
|
|
|
setup_light_platform()
|
|
|
|
|
|
|
|
|
|
platform.init()
|
|
|
|
|
assert await async_setup_component(
|
|
|
|
|
hass, light.DOMAIN, {light.DOMAIN: {CONF_PLATFORM: "test"}}
|
|
|
|
|
)
|
|
|
|
|
await hass.async_block_till_done()
|
|
|
|
|
|
|
|
|
|
ent1, _, _ = platform.ENTITIES
|
|
|
|
|
ent1, _, _ = mock_light_entities
|
|
|
|
|
|
|
|
|
|
# turn off the light by setting brightness to 0, this should work even if the light
|
|
|
|
|
# doesn't support brightness
|
|
|
|
|