diff --git a/homeassistant/components/template/light.py b/homeassistant/components/template/light.py index f10e6c2ea09..db1c89921d1 100644 --- a/homeassistant/components/template/light.py +++ b/homeassistant/components/template/light.py @@ -13,11 +13,10 @@ from homeassistant.components.light import ( ATTR_HS_COLOR, ATTR_TRANSITION, ENTITY_ID_FORMAT, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, - SUPPORT_COLOR_TEMP, + ColorMode, LightEntity, LightEntityFeature, + filter_supported_color_modes, ) from homeassistant.const import ( CONF_ENTITY_ID, @@ -182,10 +181,22 @@ class LightTemplate(TemplateEntity, LightEntity): self._color = None self._effect = None self._effect_list = None + self._fixed_color_mode = None self._max_mireds = None self._min_mireds = None self._supports_transition = False + color_modes = {ColorMode.ONOFF} + if self._level_script is not None: + color_modes.add(ColorMode.BRIGHTNESS) + if self._temperature_script is not None: + color_modes.add(ColorMode.COLOR_TEMP) + if self._color_script is not None: + color_modes.add(ColorMode.HS) + self._supported_color_modes = filter_supported_color_modes(color_modes) + if len(self._supported_color_modes) == 1: + self._fixed_color_mode = next(iter(self._supported_color_modes)) + @property def brightness(self) -> int | None: """Return the brightness of the light.""" @@ -227,16 +238,25 @@ class LightTemplate(TemplateEntity, LightEntity): """Return the effect list.""" return self._effect_list + @property + def color_mode(self): + """Return current color mode.""" + if self._fixed_color_mode: + return self._fixed_color_mode + # Support for ct + hs, prioritize hs + if self._color is not None: + return ColorMode.HS + return ColorMode.COLOR_TEMP + + @property + def supported_color_modes(self): + """Flag supported color modes.""" + return self._supported_color_modes + @property def supported_features(self) -> int: """Flag supported features.""" supported_features = 0 - if self._level_script is not None: - supported_features |= SUPPORT_BRIGHTNESS - if self._temperature_script is not None: - supported_features |= SUPPORT_COLOR_TEMP - if self._color_script is not None: - supported_features |= SUPPORT_COLOR if self._effect_script is not None: supported_features |= LightEntityFeature.EFFECT if self._supports_transition is True: diff --git a/tests/components/template/test_light.py b/tests/components/template/test_light.py index 1199a318626..89fcc97e2f7 100644 --- a/tests/components/template/test_light.py +++ b/tests/components/template/test_light.py @@ -9,9 +9,6 @@ from homeassistant.components.light import ( ATTR_EFFECT, ATTR_HS_COLOR, ATTR_TRANSITION, - SUPPORT_BRIGHTNESS, - SUPPORT_COLOR, - SUPPORT_COLOR_TEMP, SUPPORT_TRANSITION, ColorMode, LightEntityFeature, @@ -115,7 +112,7 @@ async def setup_light(hass, count, light_config): @pytest.mark.parametrize("count", [1]) @pytest.mark.parametrize( "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], + [(0, [ColorMode.BRIGHTNESS])], ) @pytest.mark.parametrize( "light_config", @@ -140,10 +137,6 @@ async def test_template_state_invalid( @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -155,18 +148,16 @@ async def test_template_state_invalid( }, ], ) -async def test_template_state_text( - hass, supported_features, supported_color_modes, setup_light -): +async def test_template_state_text(hass, setup_light): """Test the state text of a template.""" set_state = STATE_ON hass.states.async_set("light.test_state", set_state) await hass.async_block_till_done() state = hass.states.get("light.test_template_light") assert state.state == set_state - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 set_state = STATE_OFF hass.states.async_set("light.test_state", set_state) @@ -174,22 +165,18 @@ async def test_template_state_text( state = hass.states.get("light.test_template_light") assert state.state == set_state assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "value_template,expected_state,expected_color_mode", [ ( "{{ 1 == 1 }}", STATE_ON, - ColorMode.UNKNOWN, + ColorMode.BRIGHTNESS, ), ( "{{ 1 == 2 }}", @@ -202,8 +189,6 @@ async def test_templatex_state_boolean( hass, expected_color_mode, expected_state, - supported_features, - supported_color_modes, count, value_template, ): @@ -218,8 +203,8 @@ async def test_templatex_state_boolean( state = hass.states.get("light.test_template_light") assert state.state == expected_state assert state.attributes.get("color_mode") == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [0]) @@ -279,10 +264,6 @@ async def test_missing_key(hass, count, setup_light): @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -294,9 +275,7 @@ async def test_missing_key(hass, count, setup_light): }, ], ) -async def test_on_action( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_on_action(hass, setup_light, calls): """Test on action.""" hass.states.async_set("light.test_state", STATE_OFF) await hass.async_block_till_done() @@ -304,8 +283,8 @@ async def test_on_action( state = hass.states.get("light.test_template_light") assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 await hass.services.async_call( light.DOMAIN, @@ -320,15 +299,11 @@ async def test_on_action( assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -358,9 +333,7 @@ async def test_on_action( }, ], ) -async def test_on_action_with_transition( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_on_action_with_transition(hass, setup_light, calls): """Test on action with transition.""" hass.states.async_set("light.test_state", STATE_OFF) await hass.async_block_till_done() @@ -368,8 +341,8 @@ async def test_on_action_with_transition( state = hass.states.get("light.test_template_light") assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == SUPPORT_TRANSITION await hass.services.async_call( light.DOMAIN, @@ -383,15 +356,11 @@ async def test_on_action_with_transition( assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == SUPPORT_TRANSITION @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes,expected_color_mode", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS], ColorMode.BRIGHTNESS)], -) @pytest.mark.parametrize( "light_config", [ @@ -406,9 +375,6 @@ async def test_on_action_optimistic( hass, setup_light, calls, - supported_features, - supported_color_modes, - expected_color_mode, ): """Test on action with optimistic state.""" hass.states.async_set("light.test_state", STATE_OFF) @@ -417,8 +383,8 @@ async def test_on_action_optimistic( state = hass.states.get("light.test_template_light") assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 await hass.services.async_call( light.DOMAIN, @@ -432,9 +398,9 @@ async def test_on_action_optimistic( assert calls[-1].data["action"] == "turn_on" assert calls[-1].data["caller"] == "light.test_template_light" assert state.state == STATE_ON - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 await hass.services.async_call( light.DOMAIN, @@ -449,16 +415,12 @@ async def test_on_action_optimistic( assert calls[-1].data["brightness"] == 100 assert calls[-1].data["caller"] == "light.test_template_light" assert state.state == STATE_ON - assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -470,18 +432,16 @@ async def test_on_action_optimistic( }, ], ) -async def test_off_action( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_off_action(hass, setup_light, calls): """Test off action.""" hass.states.async_set("light.test_state", STATE_ON) await hass.async_block_till_done() state = hass.states.get("light.test_template_light") assert state.state == STATE_ON - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 await hass.services.async_call( light.DOMAIN, @@ -494,16 +454,12 @@ async def test_off_action( assert calls[-1].data["action"] == "turn_off" assert calls[-1].data["caller"] == "light.test_template_light" assert state.state == STATE_ON - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [(1)]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -533,18 +489,16 @@ async def test_off_action( }, ], ) -async def test_off_action_with_transition( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_off_action_with_transition(hass, setup_light, calls): """Test off action with transition.""" hass.states.async_set("light.test_state", STATE_ON) await hass.async_block_till_done() state = hass.states.get("light.test_template_light") assert state.state == STATE_ON - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == SUPPORT_TRANSITION await hass.services.async_call( light.DOMAIN, @@ -556,16 +510,12 @@ async def test_off_action_with_transition( assert len(calls) == 1 assert calls[0].data["transition"] == 2 assert state.state == STATE_ON - assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == SUPPORT_TRANSITION @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) @pytest.mark.parametrize( "light_config", [ @@ -576,15 +526,13 @@ async def test_off_action_with_transition( }, ], ) -async def test_off_action_optimistic( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_off_action_optimistic(hass, setup_light, calls): """Test off action with optimistic state.""" state = hass.states.get("light.test_template_light") assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 await hass.services.async_call( light.DOMAIN, @@ -597,15 +545,11 @@ async def test_off_action_optimistic( state = hass.states.get("light.test_template_light") assert state.state == STATE_OFF assert "color_mode" not in state.attributes - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes,expected_color_mode", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS], ColorMode.BRIGHTNESS)], -) @pytest.mark.parametrize( "light_config", [ @@ -621,9 +565,6 @@ async def test_level_action_no_template( hass, setup_light, calls, - supported_features, - supported_color_modes, - expected_color_mode, ): """Test setting brightness with optimistic template.""" state = hass.states.get("light.test_template_light") @@ -644,9 +585,9 @@ async def test_level_action_no_template( state = hass.states.get("light.test_template_light") assert state.state == STATE_ON assert state.attributes["brightness"] == 124 - assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) @@ -654,26 +595,20 @@ async def test_level_action_no_template( "expected_level,level_template,expected_color_mode", [ (255, "{{255}}", ColorMode.BRIGHTNESS), - (None, "{{256}}", ColorMode.UNKNOWN), - (None, "{{x - 12}}", ColorMode.UNKNOWN), - (None, "{{ none }}", ColorMode.UNKNOWN), - (None, "", ColorMode.UNKNOWN), + (None, "{{256}}", ColorMode.BRIGHTNESS), + (None, "{{x - 12}}", ColorMode.BRIGHTNESS), + (None, "{{ none }}", ColorMode.BRIGHTNESS), + (None, "", ColorMode.BRIGHTNESS), ( None, "{{ state_attr('light.nolight', 'brightness') }}", - ColorMode.UNKNOWN, + ColorMode.BRIGHTNESS, ), ], ) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])], -) async def test_level_template( hass, expected_level, - supported_features, - supported_color_modes, expected_color_mode, count, level_template, @@ -691,8 +626,8 @@ async def test_level_template( assert state.attributes.get("brightness") == expected_level assert state.state == STATE_ON assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) @@ -700,22 +635,16 @@ async def test_level_template( "expected_temp,temperature_template,expected_color_mode", [ (500, "{{500}}", ColorMode.COLOR_TEMP), - (None, "{{501}}", ColorMode.UNKNOWN), - (None, "{{x - 12}}", ColorMode.UNKNOWN), - (None, "None", ColorMode.UNKNOWN), - (None, "{{ none }}", ColorMode.UNKNOWN), - (None, "", ColorMode.UNKNOWN), + (None, "{{501}}", ColorMode.COLOR_TEMP), + (None, "{{x - 12}}", ColorMode.COLOR_TEMP), + (None, "None", ColorMode.COLOR_TEMP), + (None, "{{ none }}", ColorMode.COLOR_TEMP), + (None, "", ColorMode.COLOR_TEMP), ], ) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_COLOR_TEMP, [ColorMode.COLOR_TEMP])], -) async def test_temperature_template( hass, expected_temp, - supported_features, - supported_color_modes, expected_color_mode, count, temperature_template, @@ -733,15 +662,11 @@ async def test_temperature_template( assert state.attributes.get("color_temp") == expected_temp assert state.state == STATE_ON assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes,expected_color_mode", - [(SUPPORT_COLOR_TEMP, [ColorMode.COLOR_TEMP], ColorMode.COLOR_TEMP)], -) @pytest.mark.parametrize( "light_config", [ @@ -757,9 +682,6 @@ async def test_temperature_action_no_template( hass, setup_light, calls, - supported_features, - supported_color_modes, - expected_color_mode, ): """Test setting temperature with optimistic template.""" state = hass.states.get("light.test_template_light") @@ -781,9 +703,9 @@ async def test_temperature_action_no_template( assert state is not None assert state.attributes.get("color_temp") == 345 assert state.state == STATE_ON - assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["color_mode"] == ColorMode.COLOR_TEMP + assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) @@ -867,10 +789,6 @@ async def test_entity_picture_template(hass, setup_light): @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes, expected_color_mode", - [(SUPPORT_COLOR, [ColorMode.HS], ColorMode.HS)], -) @pytest.mark.parametrize( "light_config", [ @@ -886,9 +804,6 @@ async def test_color_action_no_template( hass, setup_light, calls, - supported_features, - supported_color_modes, - expected_color_mode, ): """Test setting color with optimistic template.""" state = hass.states.get("light.test_template_light") @@ -909,10 +824,10 @@ async def test_color_action_no_template( state = hass.states.get("light.test_template_light") assert state.state == STATE_ON - assert state.attributes["color_mode"] == expected_color_mode + assert state.attributes["color_mode"] == ColorMode.HS assert state.attributes.get("hs_color") == (40, 50) - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.HS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) @@ -921,23 +836,17 @@ async def test_color_action_no_template( [ ((360, 100), "{{(360, 100)}}", ColorMode.HS), ((359.9, 99.9), "{{(359.9, 99.9)}}", ColorMode.HS), - (None, "{{(361, 100)}}", ColorMode.UNKNOWN), - (None, "{{(360, 101)}}", ColorMode.UNKNOWN), - (None, "[{{(360)}},{{null}}]", ColorMode.UNKNOWN), - (None, "{{x - 12}}", ColorMode.UNKNOWN), - (None, "", ColorMode.UNKNOWN), - (None, "{{ none }}", ColorMode.UNKNOWN), + (None, "{{(361, 100)}}", ColorMode.HS), + (None, "{{(360, 101)}}", ColorMode.HS), + (None, "[{{(360)}},{{null}}]", ColorMode.HS), + (None, "{{x - 12}}", ColorMode.HS), + (None, "", ColorMode.HS), + (None, "{{ none }}", ColorMode.HS), ], ) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_COLOR, [ColorMode.HS])], -) async def test_color_template( hass, expected_hs, - supported_features, - supported_color_modes, expected_color_mode, count, color_template, @@ -955,15 +864,11 @@ async def test_color_template( assert state.attributes.get("hs_color") == expected_hs assert state.state == STATE_ON assert state.attributes["color_mode"] == expected_color_mode - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ColorMode.HS] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1]) -@pytest.mark.parametrize( - "supported_features,supported_color_modes", - [(SUPPORT_COLOR | SUPPORT_COLOR_TEMP, [ColorMode.COLOR_TEMP, ColorMode.HS])], -) @pytest.mark.parametrize( "light_config", [ @@ -992,9 +897,7 @@ async def test_color_template( }, ], ) -async def test_color_and_temperature_actions_no_template( - hass, setup_light, calls, supported_features, supported_color_modes -): +async def test_color_and_temperature_actions_no_template(hass, setup_light, calls): """Test setting color and color temperature with optimistic template.""" state = hass.states.get("light.test_template_light") assert state.attributes.get("hs_color") is None @@ -1015,8 +918,11 @@ async def test_color_and_temperature_actions_no_template( assert state.attributes["color_mode"] == ColorMode.HS assert "color_temp" not in state.attributes assert state.attributes["hs_color"] == (40, 50) - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ + ColorMode.COLOR_TEMP, + ColorMode.HS, + ] + assert state.attributes["supported_features"] == 0 # Optimistically set color temp, light should be in color temp mode await hass.services.async_call( @@ -1033,8 +939,11 @@ async def test_color_and_temperature_actions_no_template( assert state.attributes["color_mode"] == ColorMode.COLOR_TEMP assert state.attributes["color_temp"] == 123 assert "hs_color" in state.attributes # Color temp represented as hs_color - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ + ColorMode.COLOR_TEMP, + ColorMode.HS, + ] + assert state.attributes["supported_features"] == 0 # Optimistically set color, light should again be in hs_color mode await hass.services.async_call( @@ -1052,8 +961,11 @@ async def test_color_and_temperature_actions_no_template( assert state.attributes["color_mode"] == ColorMode.HS assert "color_temp" not in state.attributes assert state.attributes["hs_color"] == (10, 20) - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ + ColorMode.COLOR_TEMP, + ColorMode.HS, + ] + assert state.attributes["supported_features"] == 0 # Optimistically set color temp, light should again be in color temp mode await hass.services.async_call( @@ -1070,8 +982,11 @@ async def test_color_and_temperature_actions_no_template( assert state.attributes["color_mode"] == ColorMode.COLOR_TEMP assert state.attributes["color_temp"] == 234 assert "hs_color" in state.attributes # Color temp represented as hs_color - assert state.attributes["supported_color_modes"] == supported_color_modes - assert state.attributes["supported_features"] == supported_features + assert state.attributes["supported_color_modes"] == [ + ColorMode.COLOR_TEMP, + ColorMode.HS, + ] + assert state.attributes["supported_features"] == 0 @pytest.mark.parametrize("count", [1])