Improve light tests for brightness step and profiles (#49887)
This commit is contained in:
parent
afe02a4ad2
commit
3a93151aa2
1 changed files with 53 additions and 4 deletions
|
@ -562,7 +562,7 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"extra_call_params, expected_params",
|
||||
"extra_call_params, expected_params_state_was_off, expected_params_state_was_on",
|
||||
(
|
||||
(
|
||||
{},
|
||||
|
@ -571,6 +571,11 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_TRANSITION: 3,
|
||||
},
|
||||
{
|
||||
light.ATTR_HS_COLOR: (50.353, 100),
|
||||
light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_TRANSITION: 3,
|
||||
},
|
||||
),
|
||||
(
|
||||
{light.ATTR_BRIGHTNESS: 22},
|
||||
|
@ -579,6 +584,10 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
light.ATTR_BRIGHTNESS: 22,
|
||||
light.ATTR_TRANSITION: 3,
|
||||
},
|
||||
{
|
||||
light.ATTR_BRIGHTNESS: 22,
|
||||
light.ATTR_TRANSITION: 3,
|
||||
},
|
||||
),
|
||||
(
|
||||
{light.ATTR_TRANSITION: 22},
|
||||
|
@ -587,6 +596,9 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
light.ATTR_BRIGHTNESS: 100,
|
||||
light.ATTR_TRANSITION: 22,
|
||||
},
|
||||
{
|
||||
light.ATTR_TRANSITION: 22,
|
||||
},
|
||||
),
|
||||
(
|
||||
{
|
||||
|
@ -599,6 +611,11 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
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},
|
||||
|
@ -607,11 +624,19 @@ async def test_default_profiles_group(hass, mock_light_profiles):
|
|||
light.ATTR_BRIGHTNESS: 11,
|
||||
light.ATTR_TRANSITION: 1,
|
||||
},
|
||||
{
|
||||
light.ATTR_BRIGHTNESS: 11,
|
||||
light.ATTR_TRANSITION: 1,
|
||||
},
|
||||
),
|
||||
),
|
||||
)
|
||||
async def test_default_profiles_light(
|
||||
hass, mock_light_profiles, extra_call_params, expected_params
|
||||
hass,
|
||||
mock_light_profiles,
|
||||
extra_call_params,
|
||||
expected_params_state_was_off,
|
||||
expected_params_state_was_on,
|
||||
):
|
||||
"""Test default turn-on light profile for a specific light."""
|
||||
platform = getattr(hass.components, "test.light")
|
||||
|
@ -639,14 +664,26 @@ async def test_default_profiles_light(
|
|||
)
|
||||
|
||||
_, data = dev.last_call("turn_on")
|
||||
assert data == expected_params
|
||||
assert data == expected_params_state_was_off
|
||||
|
||||
await hass.services.async_call(
|
||||
light.DOMAIN,
|
||||
SERVICE_TURN_ON,
|
||||
{
|
||||
ATTR_ENTITY_ID: dev.entity_id,
|
||||
light.ATTR_BRIGHTNESS: 0,
|
||||
**extra_call_params,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
_, data = dev.last_call("turn_on")
|
||||
assert data == expected_params_state_was_on
|
||||
|
||||
await hass.services.async_call(
|
||||
light.DOMAIN,
|
||||
SERVICE_TURN_OFF,
|
||||
{
|
||||
ATTR_ENTITY_ID: dev.entity_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
@ -752,6 +789,18 @@ async def test_light_brightness_step(hass):
|
|||
_, data = entity1.last_call("turn_on")
|
||||
assert data["brightness"] == 66 # 40 + (255 * 0.10)
|
||||
|
||||
await hass.services.async_call(
|
||||
"light",
|
||||
"turn_on",
|
||||
{
|
||||
"entity_id": entity0.entity_id,
|
||||
"brightness_step": -126,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
assert entity0.state == "off" # 126 - 126; brightness is 0, light should turn off
|
||||
|
||||
|
||||
async def test_light_brightness_pct_conversion(hass):
|
||||
"""Test that light brightness percent conversion."""
|
||||
|
|
Loading…
Add table
Reference in a new issue