mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 17:57:11 +00:00
Remove use of deprecated SUPPORT_* constants from Template light (#77836)
This commit is contained in:
parent
b21f8c9ea8
commit
c134bcc536
@ -13,11 +13,10 @@ from homeassistant.components.light import (
|
|||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
ENTITY_ID_FORMAT,
|
ENTITY_ID_FORMAT,
|
||||||
SUPPORT_BRIGHTNESS,
|
ColorMode,
|
||||||
SUPPORT_COLOR,
|
|
||||||
SUPPORT_COLOR_TEMP,
|
|
||||||
LightEntity,
|
LightEntity,
|
||||||
LightEntityFeature,
|
LightEntityFeature,
|
||||||
|
filter_supported_color_modes,
|
||||||
)
|
)
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
CONF_ENTITY_ID,
|
CONF_ENTITY_ID,
|
||||||
@ -182,10 +181,22 @@ class LightTemplate(TemplateEntity, LightEntity):
|
|||||||
self._color = None
|
self._color = None
|
||||||
self._effect = None
|
self._effect = None
|
||||||
self._effect_list = None
|
self._effect_list = None
|
||||||
|
self._fixed_color_mode = None
|
||||||
self._max_mireds = None
|
self._max_mireds = None
|
||||||
self._min_mireds = None
|
self._min_mireds = None
|
||||||
self._supports_transition = False
|
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
|
@property
|
||||||
def brightness(self) -> int | None:
|
def brightness(self) -> int | None:
|
||||||
"""Return the brightness of the light."""
|
"""Return the brightness of the light."""
|
||||||
@ -227,16 +238,25 @@ class LightTemplate(TemplateEntity, LightEntity):
|
|||||||
"""Return the effect list."""
|
"""Return the effect list."""
|
||||||
return self._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
|
@property
|
||||||
def supported_features(self) -> int:
|
def supported_features(self) -> int:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
supported_features = 0
|
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:
|
if self._effect_script is not None:
|
||||||
supported_features |= LightEntityFeature.EFFECT
|
supported_features |= LightEntityFeature.EFFECT
|
||||||
if self._supports_transition is True:
|
if self._supports_transition is True:
|
||||||
|
@ -9,9 +9,6 @@ from homeassistant.components.light import (
|
|||||||
ATTR_EFFECT,
|
ATTR_EFFECT,
|
||||||
ATTR_HS_COLOR,
|
ATTR_HS_COLOR,
|
||||||
ATTR_TRANSITION,
|
ATTR_TRANSITION,
|
||||||
SUPPORT_BRIGHTNESS,
|
|
||||||
SUPPORT_COLOR,
|
|
||||||
SUPPORT_COLOR_TEMP,
|
|
||||||
SUPPORT_TRANSITION,
|
SUPPORT_TRANSITION,
|
||||||
ColorMode,
|
ColorMode,
|
||||||
LightEntityFeature,
|
LightEntityFeature,
|
||||||
@ -115,7 +112,7 @@ async def setup_light(hass, count, light_config):
|
|||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"supported_features,supported_color_modes",
|
"supported_features,supported_color_modes",
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
[(0, [ColorMode.BRIGHTNESS])],
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
@ -140,10 +137,6 @@ async def test_template_state_invalid(
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -155,18 +148,16 @@ async def test_template_state_invalid(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_template_state_text(
|
async def test_template_state_text(hass, setup_light):
|
||||||
hass, supported_features, supported_color_modes, setup_light
|
|
||||||
):
|
|
||||||
"""Test the state text of a template."""
|
"""Test the state text of a template."""
|
||||||
set_state = STATE_ON
|
set_state = STATE_ON
|
||||||
hass.states.async_set("light.test_state", set_state)
|
hass.states.async_set("light.test_state", set_state)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == set_state
|
assert state.state == set_state
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
set_state = STATE_OFF
|
set_state = STATE_OFF
|
||||||
hass.states.async_set("light.test_state", set_state)
|
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")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == set_state
|
assert state.state == set_state
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"value_template,expected_state,expected_color_mode",
|
"value_template,expected_state,expected_color_mode",
|
||||||
[
|
[
|
||||||
(
|
(
|
||||||
"{{ 1 == 1 }}",
|
"{{ 1 == 1 }}",
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
ColorMode.UNKNOWN,
|
ColorMode.BRIGHTNESS,
|
||||||
),
|
),
|
||||||
(
|
(
|
||||||
"{{ 1 == 2 }}",
|
"{{ 1 == 2 }}",
|
||||||
@ -202,8 +189,6 @@ async def test_templatex_state_boolean(
|
|||||||
hass,
|
hass,
|
||||||
expected_color_mode,
|
expected_color_mode,
|
||||||
expected_state,
|
expected_state,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
count,
|
count,
|
||||||
value_template,
|
value_template,
|
||||||
):
|
):
|
||||||
@ -218,8 +203,8 @@ async def test_templatex_state_boolean(
|
|||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == expected_state
|
assert state.state == expected_state
|
||||||
assert state.attributes.get("color_mode") == expected_color_mode
|
assert state.attributes.get("color_mode") == expected_color_mode
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [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("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -294,9 +275,7 @@ async def test_missing_key(hass, count, setup_light):
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_on_action(
|
async def test_on_action(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test on action."""
|
"""Test on action."""
|
||||||
hass.states.async_set("light.test_state", STATE_OFF)
|
hass.states.async_set("light.test_state", STATE_OFF)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
@ -304,8 +283,8 @@ async def test_on_action(
|
|||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -320,15 +299,11 @@ async def test_on_action(
|
|||||||
|
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -358,9 +333,7 @@ async def test_on_action(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_on_action_with_transition(
|
async def test_on_action_with_transition(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test on action with transition."""
|
"""Test on action with transition."""
|
||||||
hass.states.async_set("light.test_state", STATE_OFF)
|
hass.states.async_set("light.test_state", STATE_OFF)
|
||||||
await hass.async_block_till_done()
|
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")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == SUPPORT_TRANSITION
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -383,15 +356,11 @@ async def test_on_action_with_transition(
|
|||||||
|
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == SUPPORT_TRANSITION
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@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(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -406,9 +375,6 @@ async def test_on_action_optimistic(
|
|||||||
hass,
|
hass,
|
||||||
setup_light,
|
setup_light,
|
||||||
calls,
|
calls,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
|
||||||
):
|
):
|
||||||
"""Test on action with optimistic state."""
|
"""Test on action with optimistic state."""
|
||||||
hass.states.async_set("light.test_state", STATE_OFF)
|
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")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -432,9 +398,9 @@ async def test_on_action_optimistic(
|
|||||||
assert calls[-1].data["action"] == "turn_on"
|
assert calls[-1].data["action"] == "turn_on"
|
||||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -449,16 +415,12 @@ async def test_on_action_optimistic(
|
|||||||
assert calls[-1].data["brightness"] == 100
|
assert calls[-1].data["brightness"] == 100
|
||||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -470,18 +432,16 @@ async def test_on_action_optimistic(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_off_action(
|
async def test_off_action(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test off action."""
|
"""Test off action."""
|
||||||
hass.states.async_set("light.test_state", STATE_ON)
|
hass.states.async_set("light.test_state", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -494,16 +454,12 @@ async def test_off_action(
|
|||||||
assert calls[-1].data["action"] == "turn_off"
|
assert calls[-1].data["action"] == "turn_off"
|
||||||
assert calls[-1].data["caller"] == "light.test_template_light"
|
assert calls[-1].data["caller"] == "light.test_template_light"
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [(1)])
|
@pytest.mark.parametrize("count", [(1)])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS | SUPPORT_TRANSITION, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -533,18 +489,16 @@ async def test_off_action(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_off_action_with_transition(
|
async def test_off_action_with_transition(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test off action with transition."""
|
"""Test off action with transition."""
|
||||||
hass.states.async_set("light.test_state", STATE_ON)
|
hass.states.async_set("light.test_state", STATE_ON)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == SUPPORT_TRANSITION
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -556,16 +510,12 @@ async def test_off_action_with_transition(
|
|||||||
assert len(calls) == 1
|
assert len(calls) == 1
|
||||||
assert calls[0].data["transition"] == 2
|
assert calls[0].data["transition"] == 2
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == ColorMode.UNKNOWN # Brightness is None
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == SUPPORT_TRANSITION
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_BRIGHTNESS, [ColorMode.BRIGHTNESS])],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -576,15 +526,13 @@ async def test_off_action_with_transition(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_off_action_optimistic(
|
async def test_off_action_optimistic(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test off action with optimistic state."""
|
"""Test off action with optimistic state."""
|
||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
await hass.services.async_call(
|
await hass.services.async_call(
|
||||||
light.DOMAIN,
|
light.DOMAIN,
|
||||||
@ -597,15 +545,11 @@ async def test_off_action_optimistic(
|
|||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_OFF
|
assert state.state == STATE_OFF
|
||||||
assert "color_mode" not in state.attributes
|
assert "color_mode" not in state.attributes
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@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(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -621,9 +565,6 @@ async def test_level_action_no_template(
|
|||||||
hass,
|
hass,
|
||||||
setup_light,
|
setup_light,
|
||||||
calls,
|
calls,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
|
||||||
):
|
):
|
||||||
"""Test setting brightness with optimistic template."""
|
"""Test setting brightness with optimistic template."""
|
||||||
state = hass.states.get("light.test_template_light")
|
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")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["brightness"] == 124
|
assert state.attributes["brightness"] == 124
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == ColorMode.BRIGHTNESS
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@ -654,26 +595,20 @@ async def test_level_action_no_template(
|
|||||||
"expected_level,level_template,expected_color_mode",
|
"expected_level,level_template,expected_color_mode",
|
||||||
[
|
[
|
||||||
(255, "{{255}}", ColorMode.BRIGHTNESS),
|
(255, "{{255}}", ColorMode.BRIGHTNESS),
|
||||||
(None, "{{256}}", ColorMode.UNKNOWN),
|
(None, "{{256}}", ColorMode.BRIGHTNESS),
|
||||||
(None, "{{x - 12}}", ColorMode.UNKNOWN),
|
(None, "{{x - 12}}", ColorMode.BRIGHTNESS),
|
||||||
(None, "{{ none }}", ColorMode.UNKNOWN),
|
(None, "{{ none }}", ColorMode.BRIGHTNESS),
|
||||||
(None, "", ColorMode.UNKNOWN),
|
(None, "", ColorMode.BRIGHTNESS),
|
||||||
(
|
(
|
||||||
None,
|
None,
|
||||||
"{{ state_attr('light.nolight', 'brightness') }}",
|
"{{ 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(
|
async def test_level_template(
|
||||||
hass,
|
hass,
|
||||||
expected_level,
|
expected_level,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
expected_color_mode,
|
||||||
count,
|
count,
|
||||||
level_template,
|
level_template,
|
||||||
@ -691,8 +626,8 @@ async def test_level_template(
|
|||||||
assert state.attributes.get("brightness") == expected_level
|
assert state.attributes.get("brightness") == expected_level
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == expected_color_mode
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.BRIGHTNESS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@ -700,22 +635,16 @@ async def test_level_template(
|
|||||||
"expected_temp,temperature_template,expected_color_mode",
|
"expected_temp,temperature_template,expected_color_mode",
|
||||||
[
|
[
|
||||||
(500, "{{500}}", ColorMode.COLOR_TEMP),
|
(500, "{{500}}", ColorMode.COLOR_TEMP),
|
||||||
(None, "{{501}}", ColorMode.UNKNOWN),
|
(None, "{{501}}", ColorMode.COLOR_TEMP),
|
||||||
(None, "{{x - 12}}", ColorMode.UNKNOWN),
|
(None, "{{x - 12}}", ColorMode.COLOR_TEMP),
|
||||||
(None, "None", ColorMode.UNKNOWN),
|
(None, "None", ColorMode.COLOR_TEMP),
|
||||||
(None, "{{ none }}", ColorMode.UNKNOWN),
|
(None, "{{ none }}", ColorMode.COLOR_TEMP),
|
||||||
(None, "", ColorMode.UNKNOWN),
|
(None, "", ColorMode.COLOR_TEMP),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_COLOR_TEMP, [ColorMode.COLOR_TEMP])],
|
|
||||||
)
|
|
||||||
async def test_temperature_template(
|
async def test_temperature_template(
|
||||||
hass,
|
hass,
|
||||||
expected_temp,
|
expected_temp,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
expected_color_mode,
|
||||||
count,
|
count,
|
||||||
temperature_template,
|
temperature_template,
|
||||||
@ -733,15 +662,11 @@ async def test_temperature_template(
|
|||||||
assert state.attributes.get("color_temp") == expected_temp
|
assert state.attributes.get("color_temp") == expected_temp
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == expected_color_mode
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@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(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -757,9 +682,6 @@ async def test_temperature_action_no_template(
|
|||||||
hass,
|
hass,
|
||||||
setup_light,
|
setup_light,
|
||||||
calls,
|
calls,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
|
||||||
):
|
):
|
||||||
"""Test setting temperature with optimistic template."""
|
"""Test setting temperature with optimistic template."""
|
||||||
state = hass.states.get("light.test_template_light")
|
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 is not None
|
||||||
assert state.attributes.get("color_temp") == 345
|
assert state.attributes.get("color_temp") == 345
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == ColorMode.COLOR_TEMP
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.COLOR_TEMP]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@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("count", [1])
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes, expected_color_mode",
|
|
||||||
[(SUPPORT_COLOR, [ColorMode.HS], ColorMode.HS)],
|
|
||||||
)
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -886,9 +804,6 @@ async def test_color_action_no_template(
|
|||||||
hass,
|
hass,
|
||||||
setup_light,
|
setup_light,
|
||||||
calls,
|
calls,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
|
||||||
):
|
):
|
||||||
"""Test setting color with optimistic template."""
|
"""Test setting color with optimistic template."""
|
||||||
state = hass.states.get("light.test_template_light")
|
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")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.state == STATE_ON
|
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.get("hs_color") == (40, 50)
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
@ -921,23 +836,17 @@ async def test_color_action_no_template(
|
|||||||
[
|
[
|
||||||
((360, 100), "{{(360, 100)}}", ColorMode.HS),
|
((360, 100), "{{(360, 100)}}", ColorMode.HS),
|
||||||
((359.9, 99.9), "{{(359.9, 99.9)}}", ColorMode.HS),
|
((359.9, 99.9), "{{(359.9, 99.9)}}", ColorMode.HS),
|
||||||
(None, "{{(361, 100)}}", ColorMode.UNKNOWN),
|
(None, "{{(361, 100)}}", ColorMode.HS),
|
||||||
(None, "{{(360, 101)}}", ColorMode.UNKNOWN),
|
(None, "{{(360, 101)}}", ColorMode.HS),
|
||||||
(None, "[{{(360)}},{{null}}]", ColorMode.UNKNOWN),
|
(None, "[{{(360)}},{{null}}]", ColorMode.HS),
|
||||||
(None, "{{x - 12}}", ColorMode.UNKNOWN),
|
(None, "{{x - 12}}", ColorMode.HS),
|
||||||
(None, "", ColorMode.UNKNOWN),
|
(None, "", ColorMode.HS),
|
||||||
(None, "{{ none }}", ColorMode.UNKNOWN),
|
(None, "{{ none }}", ColorMode.HS),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@pytest.mark.parametrize(
|
|
||||||
"supported_features,supported_color_modes",
|
|
||||||
[(SUPPORT_COLOR, [ColorMode.HS])],
|
|
||||||
)
|
|
||||||
async def test_color_template(
|
async def test_color_template(
|
||||||
hass,
|
hass,
|
||||||
expected_hs,
|
expected_hs,
|
||||||
supported_features,
|
|
||||||
supported_color_modes,
|
|
||||||
expected_color_mode,
|
expected_color_mode,
|
||||||
count,
|
count,
|
||||||
color_template,
|
color_template,
|
||||||
@ -955,15 +864,11 @@ async def test_color_template(
|
|||||||
assert state.attributes.get("hs_color") == expected_hs
|
assert state.attributes.get("hs_color") == expected_hs
|
||||||
assert state.state == STATE_ON
|
assert state.state == STATE_ON
|
||||||
assert state.attributes["color_mode"] == expected_color_mode
|
assert state.attributes["color_mode"] == expected_color_mode
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||||
assert state.attributes["supported_features"] == supported_features
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@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(
|
@pytest.mark.parametrize(
|
||||||
"light_config",
|
"light_config",
|
||||||
[
|
[
|
||||||
@ -992,9 +897,7 @@ async def test_color_template(
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_color_and_temperature_actions_no_template(
|
async def test_color_and_temperature_actions_no_template(hass, setup_light, calls):
|
||||||
hass, setup_light, calls, supported_features, supported_color_modes
|
|
||||||
):
|
|
||||||
"""Test setting color and color temperature with optimistic template."""
|
"""Test setting color and color temperature with optimistic template."""
|
||||||
state = hass.states.get("light.test_template_light")
|
state = hass.states.get("light.test_template_light")
|
||||||
assert state.attributes.get("hs_color") is None
|
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 state.attributes["color_mode"] == ColorMode.HS
|
||||||
assert "color_temp" not in state.attributes
|
assert "color_temp" not in state.attributes
|
||||||
assert state.attributes["hs_color"] == (40, 50)
|
assert state.attributes["hs_color"] == (40, 50)
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [
|
||||||
assert state.attributes["supported_features"] == supported_features
|
ColorMode.COLOR_TEMP,
|
||||||
|
ColorMode.HS,
|
||||||
|
]
|
||||||
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
# Optimistically set color temp, light should be in color temp mode
|
# Optimistically set color temp, light should be in color temp mode
|
||||||
await hass.services.async_call(
|
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_mode"] == ColorMode.COLOR_TEMP
|
||||||
assert state.attributes["color_temp"] == 123
|
assert state.attributes["color_temp"] == 123
|
||||||
assert "hs_color" in state.attributes # Color temp represented as hs_color
|
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_color_modes"] == [
|
||||||
assert state.attributes["supported_features"] == supported_features
|
ColorMode.COLOR_TEMP,
|
||||||
|
ColorMode.HS,
|
||||||
|
]
|
||||||
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
# Optimistically set color, light should again be in hs_color mode
|
# Optimistically set color, light should again be in hs_color mode
|
||||||
await hass.services.async_call(
|
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 state.attributes["color_mode"] == ColorMode.HS
|
||||||
assert "color_temp" not in state.attributes
|
assert "color_temp" not in state.attributes
|
||||||
assert state.attributes["hs_color"] == (10, 20)
|
assert state.attributes["hs_color"] == (10, 20)
|
||||||
assert state.attributes["supported_color_modes"] == supported_color_modes
|
assert state.attributes["supported_color_modes"] == [
|
||||||
assert state.attributes["supported_features"] == supported_features
|
ColorMode.COLOR_TEMP,
|
||||||
|
ColorMode.HS,
|
||||||
|
]
|
||||||
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
# Optimistically set color temp, light should again be in color temp mode
|
# Optimistically set color temp, light should again be in color temp mode
|
||||||
await hass.services.async_call(
|
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_mode"] == ColorMode.COLOR_TEMP
|
||||||
assert state.attributes["color_temp"] == 234
|
assert state.attributes["color_temp"] == 234
|
||||||
assert "hs_color" in state.attributes # Color temp represented as hs_color
|
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_color_modes"] == [
|
||||||
assert state.attributes["supported_features"] == supported_features
|
ColorMode.COLOR_TEMP,
|
||||||
|
ColorMode.HS,
|
||||||
|
]
|
||||||
|
assert state.attributes["supported_features"] == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize("count", [1])
|
@pytest.mark.parametrize("count", [1])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user