From 3a93151aa2bd55059aba02b4e276e275a382bb66 Mon Sep 17 00:00:00 2001 From: karliemeads <68717336+karliemeads@users.noreply.github.com> Date: Tue, 11 May 2021 17:31:36 -0400 Subject: [PATCH] Improve light tests for brightness step and profiles (#49887) --- tests/components/light/test_init.py | 57 +++++++++++++++++++++++++++-- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/tests/components/light/test_init.py b/tests/components/light/test_init.py index ef781b56a56..432959b67e4 100644 --- a/tests/components/light/test_init.py +++ b/tests/components/light/test_init.py @@ -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."""