Always apply default light profiles, unless a profile is given (#45450)
This commit is contained in:
parent
431b143eec
commit
daf24dc508
2 changed files with 69 additions and 6 deletions
|
@ -207,9 +207,6 @@ async def async_setup(hass, config):
|
||||||
"""
|
"""
|
||||||
params = call.data["params"]
|
params = call.data["params"]
|
||||||
|
|
||||||
if not params:
|
|
||||||
profiles.apply_default(light.entity_id, params)
|
|
||||||
|
|
||||||
# Only process params once we processed brightness step
|
# Only process params once we processed brightness step
|
||||||
if params and (
|
if params and (
|
||||||
ATTR_BRIGHTNESS_STEP in params or ATTR_BRIGHTNESS_STEP_PCT in params
|
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)
|
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
|
# Zero brightness: Light will be turned off
|
||||||
if params.get(ATTR_BRIGHTNESS) == 0:
|
if params.get(ATTR_BRIGHTNESS) == 0:
|
||||||
await light.async_turn_off(**filter_turn_off_params(params))
|
await light.async_turn_off(**filter_turn_off_params(params))
|
||||||
|
|
|
@ -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."""
|
"""Test default turn-on light profile for a specific light."""
|
||||||
platform = getattr(hass.components, "test.light")
|
platform = getattr(hass.components, "test.light")
|
||||||
platform.init()
|
platform.init()
|
||||||
|
@ -582,14 +633,26 @@ async def test_default_profiles_light(hass, mock_light_profiles):
|
||||||
SERVICE_TURN_ON,
|
SERVICE_TURN_ON,
|
||||||
{
|
{
|
||||||
ATTR_ENTITY_ID: dev.entity_id,
|
ATTR_ENTITY_ID: dev.entity_id,
|
||||||
|
**extra_call_params,
|
||||||
},
|
},
|
||||||
blocking=True,
|
blocking=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
_, data = dev.last_call("turn_on")
|
_, 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 == {
|
assert data == {
|
||||||
light.ATTR_HS_COLOR: (50.353, 100),
|
|
||||||
light.ATTR_BRIGHTNESS: 100,
|
|
||||||
light.ATTR_TRANSITION: 3,
|
light.ATTR_TRANSITION: 3,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue