mirror of
https://github.com/home-assistant/core.git
synced 2026-05-14 12:31:04 +01:00
Remove legacy light template entities (#169615)
This commit is contained in:
@@ -20,24 +20,13 @@ from homeassistant.components.light import (
|
||||
DEFAULT_MIN_KELVIN,
|
||||
DOMAIN as LIGHT_DOMAIN,
|
||||
ENTITY_ID_FORMAT,
|
||||
PLATFORM_SCHEMA as LIGHT_PLATFORM_SCHEMA,
|
||||
ColorMode,
|
||||
LightEntity,
|
||||
LightEntityFeature,
|
||||
filter_supported_color_modes,
|
||||
)
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_EFFECT,
|
||||
CONF_ENTITY_ID,
|
||||
CONF_FRIENDLY_NAME,
|
||||
CONF_LIGHTS,
|
||||
CONF_NAME,
|
||||
CONF_RGB,
|
||||
CONF_STATE,
|
||||
CONF_UNIQUE_ID,
|
||||
CONF_VALUE_TEMPLATE,
|
||||
)
|
||||
from homeassistant.const import CONF_EFFECT, CONF_NAME, CONF_RGB, CONF_STATE
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import (
|
||||
@@ -57,7 +46,6 @@ from .helpers import (
|
||||
)
|
||||
from .schemas import (
|
||||
TEMPLATE_ENTITY_COMMON_CONFIG_ENTRY_SCHEMA,
|
||||
TEMPLATE_ENTITY_COMMON_SCHEMA_LEGACY,
|
||||
TEMPLATE_ENTITY_OPTIMISTIC_SCHEMA,
|
||||
make_template_entity_common_modern_schema,
|
||||
)
|
||||
@@ -68,63 +56,29 @@ _LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Legacy
|
||||
ATTR_COLOR_TEMP = "color_temp"
|
||||
CONF_COLOR_ACTION = "set_color"
|
||||
CONF_COLOR_TEMPLATE = "color_template"
|
||||
|
||||
CONF_HS = "hs"
|
||||
CONF_HS_ACTION = "set_hs"
|
||||
CONF_HS_TEMPLATE = "hs_template"
|
||||
CONF_RGB_ACTION = "set_rgb"
|
||||
CONF_RGB_TEMPLATE = "rgb_template"
|
||||
CONF_RGBW = "rgbw"
|
||||
CONF_RGBW_ACTION = "set_rgbw"
|
||||
CONF_RGBW_TEMPLATE = "rgbw_template"
|
||||
CONF_RGBWW = "rgbww"
|
||||
CONF_RGBWW_ACTION = "set_rgbww"
|
||||
CONF_RGBWW_TEMPLATE = "rgbww_template"
|
||||
CONF_EFFECT_ACTION = "set_effect"
|
||||
CONF_EFFECT_LIST = "effect_list"
|
||||
CONF_EFFECT_LIST_TEMPLATE = "effect_list_template"
|
||||
CONF_EFFECT_TEMPLATE = "effect_template"
|
||||
CONF_LEVEL = "level"
|
||||
CONF_LEVEL_ACTION = "set_level"
|
||||
CONF_LEVEL_TEMPLATE = "level_template"
|
||||
CONF_MAX_MIREDS = "max_mireds"
|
||||
CONF_MAX_MIREDS_TEMPLATE = "max_mireds_template"
|
||||
CONF_MIN_MIREDS = "min_mireds"
|
||||
CONF_MIN_MIREDS_TEMPLATE = "min_mireds_template"
|
||||
CONF_OFF_ACTION = "turn_off"
|
||||
CONF_ON_ACTION = "turn_on"
|
||||
CONF_SUPPORTS_TRANSITION = "supports_transition"
|
||||
CONF_SUPPORTS_TRANSITION_TEMPLATE = "supports_transition_template"
|
||||
CONF_TEMPERATURE_ACTION = "set_temperature"
|
||||
CONF_TEMPERATURE = "temperature"
|
||||
CONF_TEMPERATURE_TEMPLATE = "temperature_template"
|
||||
CONF_WHITE_VALUE_ACTION = "set_white_value"
|
||||
CONF_WHITE_VALUE = "white_value"
|
||||
CONF_WHITE_VALUE_TEMPLATE = "white_value_template"
|
||||
|
||||
DEFAULT_MIN_MIREDS = 153
|
||||
DEFAULT_MAX_MIREDS = 500
|
||||
|
||||
LEGACY_FIELDS = {
|
||||
CONF_COLOR_ACTION: CONF_HS_ACTION,
|
||||
CONF_COLOR_TEMPLATE: CONF_HS,
|
||||
CONF_EFFECT_LIST_TEMPLATE: CONF_EFFECT_LIST,
|
||||
CONF_EFFECT_TEMPLATE: CONF_EFFECT,
|
||||
CONF_HS_TEMPLATE: CONF_HS,
|
||||
CONF_LEVEL_TEMPLATE: CONF_LEVEL,
|
||||
CONF_MAX_MIREDS_TEMPLATE: CONF_MAX_MIREDS,
|
||||
CONF_MIN_MIREDS_TEMPLATE: CONF_MIN_MIREDS,
|
||||
CONF_RGB_TEMPLATE: CONF_RGB,
|
||||
CONF_RGBW_TEMPLATE: CONF_RGBW,
|
||||
CONF_RGBWW_TEMPLATE: CONF_RGBWW,
|
||||
CONF_SUPPORTS_TRANSITION_TEMPLATE: CONF_SUPPORTS_TRANSITION,
|
||||
CONF_TEMPERATURE_TEMPLATE: CONF_TEMPERATURE,
|
||||
CONF_VALUE_TEMPLATE: CONF_STATE,
|
||||
CONF_WHITE_VALUE_TEMPLATE: CONF_WHITE_VALUE,
|
||||
}
|
||||
|
||||
DEFAULT_NAME = "Template Light"
|
||||
|
||||
SCRIPT_FIELDS = (
|
||||
@@ -169,49 +123,6 @@ LIGHT_YAML_SCHEMA = LIGHT_COMMON_SCHEMA.extend(
|
||||
TEMPLATE_ENTITY_OPTIMISTIC_SCHEMA
|
||||
).extend(make_template_entity_common_modern_schema(LIGHT_DOMAIN, DEFAULT_NAME).schema)
|
||||
|
||||
LIGHT_LEGACY_YAML_SCHEMA = vol.All(
|
||||
cv.deprecated(CONF_ENTITY_ID),
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Exclusive(CONF_COLOR_ACTION, "hs_legacy_action"): cv.SCRIPT_SCHEMA,
|
||||
vol.Exclusive(CONF_COLOR_TEMPLATE, "hs_legacy_template"): cv.template,
|
||||
vol.Exclusive(CONF_HS_ACTION, "hs_legacy_action"): cv.SCRIPT_SCHEMA,
|
||||
vol.Exclusive(CONF_HS_TEMPLATE, "hs_legacy_template"): cv.template,
|
||||
vol.Optional(CONF_RGB_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_RGB_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_RGBW_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_RGBW_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_RGBWW_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_RGBWW_TEMPLATE): cv.template,
|
||||
vol.Inclusive(CONF_EFFECT_ACTION, "effect"): cv.SCRIPT_SCHEMA,
|
||||
vol.Inclusive(CONF_EFFECT_LIST_TEMPLATE, "effect"): cv.template,
|
||||
vol.Inclusive(CONF_EFFECT_TEMPLATE, "effect"): cv.template,
|
||||
vol.Optional(CONF_ENTITY_ID): cv.entity_ids,
|
||||
vol.Optional(CONF_FRIENDLY_NAME): cv.string,
|
||||
vol.Optional(CONF_LEVEL_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_LEVEL_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_MAX_MIREDS_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_MIN_MIREDS_TEMPLATE): cv.template,
|
||||
vol.Required(CONF_OFF_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Required(CONF_ON_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_SUPPORTS_TRANSITION_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_TEMPERATURE_ACTION): cv.SCRIPT_SCHEMA,
|
||||
vol.Optional(CONF_TEMPERATURE_TEMPLATE): cv.template,
|
||||
vol.Optional(CONF_UNIQUE_ID): cv.string,
|
||||
vol.Optional(CONF_VALUE_TEMPLATE): cv.template,
|
||||
}
|
||||
).extend(TEMPLATE_ENTITY_COMMON_SCHEMA_LEGACY.schema),
|
||||
)
|
||||
|
||||
PLATFORM_SCHEMA = vol.All(
|
||||
# CONF_WHITE_VALUE_* is deprecated, support will be removed in release 2022.9
|
||||
cv.removed(CONF_WHITE_VALUE_ACTION),
|
||||
cv.removed(CONF_WHITE_VALUE_TEMPLATE),
|
||||
LIGHT_PLATFORM_SCHEMA.extend(
|
||||
{vol.Required(CONF_LIGHTS): cv.schema_with_slug_keys(LIGHT_LEGACY_YAML_SCHEMA)}
|
||||
),
|
||||
)
|
||||
|
||||
LIGHT_CONFIG_ENTRY_SCHEMA = LIGHT_COMMON_SCHEMA.extend(
|
||||
TEMPLATE_ENTITY_COMMON_CONFIG_ENTRY_SCHEMA.schema
|
||||
)
|
||||
@@ -232,8 +143,6 @@ async def async_setup_platform(
|
||||
TriggerLightEntity,
|
||||
async_add_entities,
|
||||
discovery_info,
|
||||
LEGACY_FIELDS,
|
||||
legacy_key=CONF_LIGHTS,
|
||||
script_options=SCRIPT_FIELDS,
|
||||
)
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ from .conftest import (
|
||||
TemplatePlatformSetup,
|
||||
assert_action,
|
||||
async_get_flow_preview_state,
|
||||
async_setup_legacy_platforms,
|
||||
async_trigger,
|
||||
make_test_action,
|
||||
make_test_trigger,
|
||||
@@ -88,15 +87,6 @@ ON_OFF_COLOR_TEMP_ACTIONS = {
|
||||
**COLOR_TEMP_ACTION,
|
||||
}
|
||||
|
||||
|
||||
ON_OFF_LEGACY_COLOR_ACTIONS = {
|
||||
**ON_OFF_ACTIONS,
|
||||
**make_test_action(
|
||||
"set_color",
|
||||
{"s": "{{ s }}", "h": "{{ h }}"},
|
||||
),
|
||||
}
|
||||
|
||||
HS_ACTION = make_test_action(
|
||||
"set_hs",
|
||||
{"s": "{{ s }}", "h": "{{ h }}"},
|
||||
@@ -297,17 +287,8 @@ async def setup_light_with_effects(
|
||||
count,
|
||||
{
|
||||
**SET_EFFECT_ACTION,
|
||||
**(
|
||||
{
|
||||
"effect_list_template": effect_list_template,
|
||||
"effect_template": effect_template,
|
||||
}
|
||||
if style == ConfigurationStyle.LEGACY
|
||||
else {
|
||||
"effect_list": effect_list_template,
|
||||
"effect": effect_template,
|
||||
}
|
||||
),
|
||||
"effect_list": effect_list_template,
|
||||
"effect": effect_template,
|
||||
},
|
||||
"{{ true }}",
|
||||
ON_OFF_ACTIONS,
|
||||
@@ -330,12 +311,8 @@ async def setup_light_with_mireds(
|
||||
count,
|
||||
{
|
||||
attribute: attribute_template,
|
||||
"temperature": "{{ 200 }}",
|
||||
**make_test_action("set_temperature", {"color_temp": "{{ color_temp }}"}),
|
||||
**(
|
||||
{"temperature_template": "{{ 200 }}"}
|
||||
if style == ConfigurationStyle.LEGACY
|
||||
else {"temperature": "{{ 200 }}"}
|
||||
),
|
||||
},
|
||||
"{{ 1==1 }}",
|
||||
ON_OFF_ACTIONS,
|
||||
@@ -357,32 +334,35 @@ async def setup_light_with_transition_template(
|
||||
count,
|
||||
{
|
||||
**SET_EFFECT_ACTION,
|
||||
**(
|
||||
{
|
||||
"effect_list_template": "{{ ['Disco', 'Police'] }}",
|
||||
"effect_template": "{{ None }}",
|
||||
"supports_transition_template": transition_template,
|
||||
}
|
||||
if style == ConfigurationStyle.LEGACY
|
||||
else {
|
||||
"effect_list": "{{ ['Disco', 'Police'] }}",
|
||||
"effect": "{{ None }}",
|
||||
"supports_transition": transition_template,
|
||||
}
|
||||
),
|
||||
"effect_list": "{{ ['Disco', 'Police'] }}",
|
||||
"effect": "{{ None }}",
|
||||
"supports_transition": transition_template,
|
||||
},
|
||||
"{{ 1==1 }}",
|
||||
ON_OFF_ACTIONS,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("count", "state_template", "style", "extra_config"),
|
||||
[(1, "{{ states('sensor.test_state') }}", ConfigurationStyle.LEGACY, {})],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_legacy_template_creates_warning(
|
||||
hass: HomeAssistant, caplog_setup_text
|
||||
) -> None:
|
||||
"""Test legacy YAML configuration logs a warning."""
|
||||
assert len(hass.states.async_all("light")) == 0
|
||||
assert "entities can only be configured under template:" in caplog_setup_text
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("count", "state_template", "extra_config"),
|
||||
[(1, "{{states.test['big.fat...']}}", {})],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_template_state_invalid(hass: HomeAssistant) -> None:
|
||||
@@ -401,7 +381,7 @@ async def test_template_state_invalid(hass: HomeAssistant) -> None:
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_template_state_text(hass: HomeAssistant) -> None:
|
||||
@@ -426,7 +406,7 @@ async def test_template_state_text(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(("count", "extra_config"), [(1, {})])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("state_template", "expected_state", "expected_color_mode"),
|
||||
@@ -459,27 +439,12 @@ async def test_template_state_boolean(
|
||||
assert state.attributes["supported_features"] == 0
|
||||
|
||||
|
||||
async def test_legacy_template_config_errors(hass: HomeAssistant) -> None:
|
||||
"""Test legacy template light configuration errors."""
|
||||
await async_setup_legacy_platforms(
|
||||
hass,
|
||||
light.DOMAIN,
|
||||
"bad name here",
|
||||
0,
|
||||
{
|
||||
**ON_OFF_SET_LEVEL_ACTIONS,
|
||||
"value_template": "{{ 1== 1}}",
|
||||
},
|
||||
)
|
||||
assert hass.states.async_all("light") == []
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("count", "state_template", "extra_config"), [(0, "{%- if false -%}", {})]
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_template_config_errors(hass: HomeAssistant) -> None:
|
||||
@@ -493,7 +458,7 @@ async def test_template_config_errors(hass: HomeAssistant) -> None:
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_light")
|
||||
async def test_missing_key(hass: HomeAssistant) -> None:
|
||||
@@ -507,7 +472,7 @@ async def test_missing_key(hass: HomeAssistant) -> None:
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_on_action(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
|
||||
@@ -532,14 +497,6 @@ async def test_on_action(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("config", "style"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"value_template": "{{states.light.test_state.state}}",
|
||||
**ON_ACTION_WITH_TRANSITION,
|
||||
"supports_transition_template": "{{true}}",
|
||||
},
|
||||
ConfigurationStyle.LEGACY,
|
||||
),
|
||||
(
|
||||
{
|
||||
"state": "{{states.light.test_state.state}}",
|
||||
@@ -584,7 +541,7 @@ async def test_on_action_with_transition(
|
||||
@pytest.mark.parametrize(("count", "config"), [(1, ON_OFF_SET_LEVEL_ACTIONS)])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_light")
|
||||
async def test_on_action_optimistic(
|
||||
@@ -629,7 +586,7 @@ async def test_on_action_optimistic(
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_off_action(hass: HomeAssistant, calls: list[ServiceCall]) -> None:
|
||||
@@ -653,14 +610,6 @@ async def test_off_action(hass: HomeAssistant, calls: list[ServiceCall]) -> None
|
||||
@pytest.mark.parametrize(
|
||||
("config", "style"),
|
||||
[
|
||||
(
|
||||
{
|
||||
"value_template": "{{states.light.test_state.state}}",
|
||||
**OFF_ACTION_WITH_TRANSITION,
|
||||
"supports_transition_template": "{{true}}",
|
||||
},
|
||||
ConfigurationStyle.LEGACY,
|
||||
),
|
||||
(
|
||||
{
|
||||
"state": "{{states.light.test_state.state}}",
|
||||
@@ -704,7 +653,7 @@ async def test_off_action_with_transition(
|
||||
@pytest.mark.parametrize(("count", "config"), [(1, ON_OFF_SET_LEVEL_ACTIONS)])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_light")
|
||||
async def test_off_action_optimistic(
|
||||
@@ -733,7 +682,7 @@ async def test_off_action_optimistic(
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_state_light")
|
||||
async def test_level_action_no_template(
|
||||
@@ -764,7 +713,6 @@ async def test_level_action_no_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "level_template"),
|
||||
(ConfigurationStyle.MODERN, "level"),
|
||||
(ConfigurationStyle.TRIGGER, "level"),
|
||||
],
|
||||
@@ -806,7 +754,6 @@ async def test_level_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "temperature_template"),
|
||||
(ConfigurationStyle.MODERN, "temperature"),
|
||||
(ConfigurationStyle.TRIGGER, "temperature"),
|
||||
],
|
||||
@@ -843,7 +790,6 @@ async def test_temperature_template(
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[
|
||||
ConfigurationStyle.LEGACY,
|
||||
ConfigurationStyle.MODERN,
|
||||
ConfigurationStyle.TRIGGER,
|
||||
],
|
||||
@@ -882,7 +828,6 @@ async def test_temperature_action_no_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute", "entity_id"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "friendly_name", TEST_LIGHT.entity_id),
|
||||
(ConfigurationStyle.MODERN, "name", "light.template_light"),
|
||||
(ConfigurationStyle.TRIGGER, "name", "light.template_light"),
|
||||
],
|
||||
@@ -901,7 +846,6 @@ async def test_friendly_name(hass: HomeAssistant, entity_id: str) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "icon_template"),
|
||||
(ConfigurationStyle.MODERN, "icon"),
|
||||
(ConfigurationStyle.TRIGGER, "icon"),
|
||||
],
|
||||
@@ -925,7 +869,6 @@ async def test_icon_template(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "entity_picture_template"),
|
||||
(ConfigurationStyle.MODERN, "picture"),
|
||||
(ConfigurationStyle.TRIGGER, "picture"),
|
||||
],
|
||||
@@ -945,82 +888,10 @@ async def test_entity_picture_template(hass: HomeAssistant) -> None:
|
||||
assert state.attributes["entity_picture"] == "/local/light.png"
|
||||
|
||||
|
||||
@pytest.mark.parametrize(("count", "extra_config"), [(1, ON_OFF_LEGACY_COLOR_ACTIONS)])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[
|
||||
ConfigurationStyle.LEGACY,
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_single_action_light")
|
||||
async def test_legacy_color_action_no_template(
|
||||
hass: HomeAssistant, calls: list[ServiceCall]
|
||||
) -> None:
|
||||
"""Test setting color with optimistic template."""
|
||||
state = hass.states.get(TEST_LIGHT.entity_id)
|
||||
assert state.attributes.get("hs_color") is None
|
||||
|
||||
await _call_and_assert_action(
|
||||
hass,
|
||||
calls,
|
||||
SERVICE_TURN_ON,
|
||||
{ATTR_HS_COLOR: (40, 50)},
|
||||
{"h": 40, "s": 50},
|
||||
"set_color",
|
||||
)
|
||||
|
||||
state = hass.states.get(TEST_LIGHT.entity_id)
|
||||
assert state.state == STATE_ON
|
||||
assert state.attributes["color_mode"] == ColorMode.HS
|
||||
assert state.attributes.get("hs_color") == (40, 50)
|
||||
assert state.attributes["supported_color_modes"] == [ColorMode.HS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("count", "style", "extra_config", "attribute"),
|
||||
[
|
||||
(
|
||||
1,
|
||||
ConfigurationStyle.LEGACY,
|
||||
ON_OFF_LEGACY_COLOR_ACTIONS,
|
||||
"color_template",
|
||||
),
|
||||
],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("expected_hs", "attribute_template", "expected_color_mode"),
|
||||
[
|
||||
((360, 100), "{{(360, 100)}}", ColorMode.HS),
|
||||
((359.9, 99.9), "{{(359.9, 99.9)}}", ColorMode.HS),
|
||||
(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),
|
||||
(None, "{{('one','two')}}", ColorMode.HS),
|
||||
],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_single_attribute_light")
|
||||
async def test_legacy_color_template(
|
||||
hass: HomeAssistant,
|
||||
expected_hs: tuple[float, float] | None,
|
||||
expected_color_mode: ColorMode,
|
||||
) -> None:
|
||||
"""Test the template for the color."""
|
||||
state = hass.states.get(TEST_LIGHT.entity_id)
|
||||
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"] == [ColorMode.HS]
|
||||
assert state.attributes["supported_features"] == 0
|
||||
|
||||
|
||||
@pytest.mark.parametrize("count", [1])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
(
|
||||
@@ -1101,7 +972,6 @@ async def test_color_actions_no_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "hs_template"),
|
||||
(ConfigurationStyle.MODERN, "hs"),
|
||||
(ConfigurationStyle.TRIGGER, "hs"),
|
||||
],
|
||||
@@ -1141,7 +1011,6 @@ async def test_hs_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "rgb_template"),
|
||||
(ConfigurationStyle.MODERN, "rgb"),
|
||||
(ConfigurationStyle.TRIGGER, "rgb"),
|
||||
],
|
||||
@@ -1182,7 +1051,6 @@ async def test_rgb_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "rgbw_template"),
|
||||
(ConfigurationStyle.MODERN, "rgbw"),
|
||||
(ConfigurationStyle.TRIGGER, "rgbw"),
|
||||
],
|
||||
@@ -1225,7 +1093,6 @@ async def test_rgbw_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "rgbww_template"),
|
||||
(ConfigurationStyle.MODERN, "rgbww"),
|
||||
(ConfigurationStyle.TRIGGER, "rgbww"),
|
||||
],
|
||||
@@ -1272,14 +1139,6 @@ async def test_rgbww_template(
|
||||
@pytest.mark.parametrize(
|
||||
("config", "style"),
|
||||
[
|
||||
(
|
||||
{
|
||||
**ON_OFF_ACTIONS,
|
||||
"value_template": "{{1 == 1}}",
|
||||
**ALL_COLOR_ACTIONS,
|
||||
},
|
||||
ConfigurationStyle.LEGACY,
|
||||
),
|
||||
(
|
||||
{
|
||||
**ON_OFF_ACTIONS,
|
||||
@@ -1464,7 +1323,7 @@ async def test_all_colors_mode_no_template(
|
||||
@pytest.mark.parametrize("count", [1])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("effect_list_template", "effect_template", "effect", "expected"),
|
||||
@@ -1501,7 +1360,7 @@ async def test_effect_action(
|
||||
@pytest.mark.parametrize(("count", "effect_template"), [(1, "{{ None }}")])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("expected_effect_list", "effect_list_template"),
|
||||
@@ -1539,7 +1398,7 @@ async def test_effect_list_template(
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
("expected_effect", "effect_template"),
|
||||
@@ -1566,7 +1425,6 @@ async def test_effect_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "min_mireds_template"),
|
||||
(ConfigurationStyle.MODERN, "min_mireds"),
|
||||
(ConfigurationStyle.TRIGGER, "min_mireds"),
|
||||
],
|
||||
@@ -1597,7 +1455,6 @@ async def test_min_mireds_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "max_mireds_template"),
|
||||
(ConfigurationStyle.MODERN, "max_mireds"),
|
||||
(ConfigurationStyle.TRIGGER, "max_mireds"),
|
||||
],
|
||||
@@ -1629,7 +1486,6 @@ async def test_max_mireds_template(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "supports_transition_template"),
|
||||
(ConfigurationStyle.MODERN, "supports_transition"),
|
||||
(ConfigurationStyle.TRIGGER, "supports_transition"),
|
||||
],
|
||||
@@ -1671,7 +1527,7 @@ async def test_supports_transition_template(
|
||||
)
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
@pytest.mark.usefixtures("setup_light_with_transition_template")
|
||||
async def test_supports_transition_template_updates(hass: HomeAssistant) -> None:
|
||||
@@ -1722,7 +1578,6 @@ async def test_supports_transition_template_updates(hass: HomeAssistant) -> None
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "availability_template"),
|
||||
(ConfigurationStyle.MODERN, "availability"),
|
||||
(ConfigurationStyle.TRIGGER, "availability"),
|
||||
],
|
||||
@@ -1762,7 +1617,6 @@ async def test_available_template_with_entities(hass: HomeAssistant) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("style", "attribute"),
|
||||
[
|
||||
(ConfigurationStyle.LEGACY, "availability_template"),
|
||||
(ConfigurationStyle.MODERN, "availability"),
|
||||
],
|
||||
)
|
||||
@@ -1778,7 +1632,7 @@ async def test_invalid_availability_template_keeps_component_available(
|
||||
@pytest.mark.parametrize("config", [ON_OFF_ACTIONS])
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[ConfigurationStyle.LEGACY, ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
[ConfigurationStyle.MODERN, ConfigurationStyle.TRIGGER],
|
||||
)
|
||||
async def test_unique_id(
|
||||
hass: HomeAssistant, style: ConfigurationStyle, config: ConfigType
|
||||
@@ -1807,7 +1661,6 @@ async def test_nested_unique_id(
|
||||
@pytest.mark.parametrize(
|
||||
"style",
|
||||
[
|
||||
ConfigurationStyle.LEGACY,
|
||||
ConfigurationStyle.MODERN,
|
||||
],
|
||||
)
|
||||
@@ -1855,13 +1708,6 @@ async def test_empty_color_mode_action_config(
|
||||
@pytest.mark.parametrize(
|
||||
("style", "extra_config"),
|
||||
[
|
||||
(
|
||||
ConfigurationStyle.LEGACY,
|
||||
{
|
||||
"effect_list_template": "{{ ['a'] }}",
|
||||
"effect_template": "{{ 'a' }}",
|
||||
},
|
||||
),
|
||||
(
|
||||
ConfigurationStyle.MODERN,
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user