1
mirror of https://github.com/home-assistant/core synced 2024-10-04 07:58:43 +02:00

Always apply default light profiles, unless a profile is given (#45450)

This commit is contained in:
Alexei Chetroi 2021-01-23 00:20:53 -05:00 committed by GitHub
parent 431b143eec
commit daf24dc508
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 6 deletions

View File

@ -207,9 +207,6 @@ async def async_setup(hass, config):
"""
params = call.data["params"]
if not params:
profiles.apply_default(light.entity_id, params)
# Only process params once we processed brightness step
if params and (
ATTR_BRIGHTNESS_STEP in params or ATTR_BRIGHTNESS_STEP_PCT in params
@ -226,6 +223,9 @@ async def async_setup(hass, config):
preprocess_turn_on_alternatives(hass, params)
if ATTR_PROFILE not in params:
profiles.apply_default(light.entity_id, params)
# Zero brightness: Light will be turned off
if params.get(ATTR_BRIGHTNESS) == 0:
await light.async_turn_off(**filter_turn_off_params(params))

View File

@ -561,7 +561,58 @@ async def test_default_profiles_group(hass, mock_light_profiles):
}
async def test_default_profiles_light(hass, mock_light_profiles):
@pytest.mark.parametrize(
"extra_call_params, expected_params",
(
(
{},
{
light.ATTR_HS_COLOR: (50.353, 100),
light.ATTR_BRIGHTNESS: 100,
light.ATTR_TRANSITION: 3,
},
),
(
{light.ATTR_BRIGHTNESS: 22},
{
light.ATTR_HS_COLOR: (50.353, 100),
light.ATTR_BRIGHTNESS: 22,
light.ATTR_TRANSITION: 3,
},
),
(
{light.ATTR_TRANSITION: 22},
{
light.ATTR_HS_COLOR: (50.353, 100),
light.ATTR_BRIGHTNESS: 100,
light.ATTR_TRANSITION: 22,
},
),
(
{
light.ATTR_XY_COLOR: [0.4448, 0.4066],
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
{
light.ATTR_HS_COLOR: (38.88, 49.02),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
(
{light.ATTR_BRIGHTNESS: 11, light.ATTR_TRANSITION: 1},
{
light.ATTR_HS_COLOR: (50.353, 100),
light.ATTR_BRIGHTNESS: 11,
light.ATTR_TRANSITION: 1,
},
),
),
)
async def test_default_profiles_light(
hass, mock_light_profiles, extra_call_params, expected_params
):
"""Test default turn-on light profile for a specific light."""
platform = getattr(hass.components, "test.light")
platform.init()
@ -582,14 +633,26 @@ async def test_default_profiles_light(hass, mock_light_profiles):
SERVICE_TURN_ON,
{
ATTR_ENTITY_ID: dev.entity_id,
**extra_call_params,
},
blocking=True,
)
_, data = dev.last_call("turn_on")
assert data == expected_params
await hass.services.async_call(
light.DOMAIN,
SERVICE_TURN_ON,
{
ATTR_ENTITY_ID: dev.entity_id,
light.ATTR_BRIGHTNESS: 0,
},
blocking=True,
)
_, data = dev.last_call("turn_off")
assert data == {
light.ATTR_HS_COLOR: (50.353, 100),
light.ATTR_BRIGHTNESS: 100,
light.ATTR_TRANSITION: 3,
}