mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Remove legacy template hass config option (#119925)
This commit is contained in:
parent
6420837d58
commit
127af149ca
@ -292,41 +292,6 @@ def _raise_issue_if_no_country(hass: HomeAssistant, country: str | None) -> None
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def _raise_issue_if_legacy_templates(
|
|
||||||
hass: HomeAssistant, legacy_templates: bool | None
|
|
||||||
) -> None:
|
|
||||||
# legacy_templates can have the following values:
|
|
||||||
# - None: Using default value (False) -> Delete repair issues
|
|
||||||
# - True: Create repair to adopt templates to new syntax
|
|
||||||
# - False: Create repair to tell user to remove config key
|
|
||||||
if legacy_templates:
|
|
||||||
ir.async_create_issue(
|
|
||||||
hass,
|
|
||||||
HA_DOMAIN,
|
|
||||||
"legacy_templates_true",
|
|
||||||
is_fixable=False,
|
|
||||||
breaks_in_ha_version="2024.7.0",
|
|
||||||
severity=ir.IssueSeverity.WARNING,
|
|
||||||
translation_key="legacy_templates_true",
|
|
||||||
)
|
|
||||||
return
|
|
||||||
|
|
||||||
ir.async_delete_issue(hass, HA_DOMAIN, "legacy_templates_true")
|
|
||||||
|
|
||||||
if legacy_templates is False:
|
|
||||||
ir.async_create_issue(
|
|
||||||
hass,
|
|
||||||
HA_DOMAIN,
|
|
||||||
"legacy_templates_false",
|
|
||||||
is_fixable=False,
|
|
||||||
breaks_in_ha_version="2024.7.0",
|
|
||||||
severity=ir.IssueSeverity.WARNING,
|
|
||||||
translation_key="legacy_templates_false",
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
ir.async_delete_issue(hass, HA_DOMAIN, "legacy_templates_false")
|
|
||||||
|
|
||||||
|
|
||||||
def _validate_currency(data: Any) -> Any:
|
def _validate_currency(data: Any) -> Any:
|
||||||
try:
|
try:
|
||||||
return cv.currency(data)
|
return cv.currency(data)
|
||||||
@ -391,7 +356,7 @@ CORE_CONFIG_SCHEMA = vol.All(
|
|||||||
_no_duplicate_auth_mfa_module,
|
_no_duplicate_auth_mfa_module,
|
||||||
),
|
),
|
||||||
vol.Optional(CONF_MEDIA_DIRS): cv.schema_with_slug_keys(vol.IsDir()),
|
vol.Optional(CONF_MEDIA_DIRS): cv.schema_with_slug_keys(vol.IsDir()),
|
||||||
vol.Optional(CONF_LEGACY_TEMPLATES): cv.boolean,
|
vol.Remove(CONF_LEGACY_TEMPLATES): cv.boolean,
|
||||||
vol.Optional(CONF_CURRENCY): _validate_currency,
|
vol.Optional(CONF_CURRENCY): _validate_currency,
|
||||||
vol.Optional(CONF_COUNTRY): cv.country,
|
vol.Optional(CONF_COUNTRY): cv.country,
|
||||||
vol.Optional(CONF_LANGUAGE): cv.language,
|
vol.Optional(CONF_LANGUAGE): cv.language,
|
||||||
@ -897,7 +862,6 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non
|
|||||||
(CONF_INTERNAL_URL, "internal_url"),
|
(CONF_INTERNAL_URL, "internal_url"),
|
||||||
(CONF_EXTERNAL_URL, "external_url"),
|
(CONF_EXTERNAL_URL, "external_url"),
|
||||||
(CONF_MEDIA_DIRS, "media_dirs"),
|
(CONF_MEDIA_DIRS, "media_dirs"),
|
||||||
(CONF_LEGACY_TEMPLATES, "legacy_templates"),
|
|
||||||
(CONF_CURRENCY, "currency"),
|
(CONF_CURRENCY, "currency"),
|
||||||
(CONF_COUNTRY, "country"),
|
(CONF_COUNTRY, "country"),
|
||||||
(CONF_LANGUAGE, "language"),
|
(CONF_LANGUAGE, "language"),
|
||||||
@ -909,7 +873,6 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non
|
|||||||
if config.get(CONF_DEBUG):
|
if config.get(CONF_DEBUG):
|
||||||
hac.debug = True
|
hac.debug = True
|
||||||
|
|
||||||
_raise_issue_if_legacy_templates(hass, config.get(CONF_LEGACY_TEMPLATES))
|
|
||||||
_raise_issue_if_historic_currency(hass, hass.config.currency)
|
_raise_issue_if_historic_currency(hass, hass.config.currency)
|
||||||
_raise_issue_if_no_country(hass, hass.config.country)
|
_raise_issue_if_no_country(hass, hass.config.country)
|
||||||
|
|
||||||
|
@ -18,7 +18,6 @@ import pytest
|
|||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components import group
|
from homeassistant.components import group
|
||||||
from homeassistant.config import async_process_ha_core_config
|
|
||||||
from homeassistant.const import (
|
from homeassistant.const import (
|
||||||
ATTR_UNIT_OF_MEASUREMENT,
|
ATTR_UNIT_OF_MEASUREMENT,
|
||||||
STATE_ON,
|
STATE_ON,
|
||||||
@ -5402,22 +5401,6 @@ async def test_unavailable_states(hass: HomeAssistant) -> None:
|
|||||||
assert tpl.async_render() == "light.none, light.unavailable, light.unknown"
|
assert tpl.async_render() == "light.none, light.unavailable, light.unknown"
|
||||||
|
|
||||||
|
|
||||||
async def test_legacy_templates(hass: HomeAssistant) -> None:
|
|
||||||
"""Test if old template behavior works when legacy templates are enabled."""
|
|
||||||
hass.states.async_set("sensor.temperature", "12")
|
|
||||||
|
|
||||||
assert (
|
|
||||||
template.Template("{{ states.sensor.temperature.state }}", hass).async_render()
|
|
||||||
== 12
|
|
||||||
)
|
|
||||||
|
|
||||||
await async_process_ha_core_config(hass, {"legacy_templates": True})
|
|
||||||
assert (
|
|
||||||
template.Template("{{ states.sensor.temperature.state }}", hass).async_render()
|
|
||||||
== "12"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_no_result_parsing(hass: HomeAssistant) -> None:
|
async def test_no_result_parsing(hass: HomeAssistant) -> None:
|
||||||
"""Test if templates results are not parsed."""
|
"""Test if templates results are not parsed."""
|
||||||
hass.states.async_set("sensor.temperature", "12")
|
hass.states.async_set("sensor.temperature", "12")
|
||||||
|
@ -864,7 +864,6 @@ async def test_loading_configuration(hass: HomeAssistant) -> None:
|
|||||||
"external_url": "https://www.example.com",
|
"external_url": "https://www.example.com",
|
||||||
"internal_url": "http://example.local",
|
"internal_url": "http://example.local",
|
||||||
"media_dirs": {"mymedia": "/usr"},
|
"media_dirs": {"mymedia": "/usr"},
|
||||||
"legacy_templates": True,
|
|
||||||
"debug": True,
|
"debug": True,
|
||||||
"currency": "EUR",
|
"currency": "EUR",
|
||||||
"country": "SE",
|
"country": "SE",
|
||||||
@ -886,7 +885,6 @@ async def test_loading_configuration(hass: HomeAssistant) -> None:
|
|||||||
assert "/usr" in hass.config.allowlist_external_dirs
|
assert "/usr" in hass.config.allowlist_external_dirs
|
||||||
assert hass.config.media_dirs == {"mymedia": "/usr"}
|
assert hass.config.media_dirs == {"mymedia": "/usr"}
|
||||||
assert hass.config.config_source is ConfigSource.YAML
|
assert hass.config.config_source is ConfigSource.YAML
|
||||||
assert hass.config.legacy_templates is True
|
|
||||||
assert hass.config.debug is True
|
assert hass.config.debug is True
|
||||||
assert hass.config.currency == "EUR"
|
assert hass.config.currency == "EUR"
|
||||||
assert hass.config.country == "SE"
|
assert hass.config.country == "SE"
|
||||||
@ -2044,32 +2042,6 @@ async def test_core_config_schema_no_country(
|
|||||||
assert issue
|
assert issue
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("config", "expected_issue"),
|
|
||||||
[
|
|
||||||
({}, None),
|
|
||||||
({"legacy_templates": True}, "legacy_templates_true"),
|
|
||||||
({"legacy_templates": False}, "legacy_templates_false"),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
async def test_core_config_schema_legacy_template(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: dict[str, Any],
|
|
||||||
expected_issue: str | None,
|
|
||||||
issue_registry: ir.IssueRegistry,
|
|
||||||
) -> None:
|
|
||||||
"""Test legacy_template core config schema."""
|
|
||||||
await config_util.async_process_ha_core_config(hass, config)
|
|
||||||
|
|
||||||
for issue_id in ("legacy_templates_true", "legacy_templates_false"):
|
|
||||||
issue = issue_registry.async_get_issue("homeassistant", issue_id)
|
|
||||||
assert issue if issue_id == expected_issue else not issue
|
|
||||||
|
|
||||||
await config_util.async_process_ha_core_config(hass, {})
|
|
||||||
for issue_id in ("legacy_templates_true", "legacy_templates_false"):
|
|
||||||
assert not issue_registry.async_get_issue("homeassistant", issue_id)
|
|
||||||
|
|
||||||
|
|
||||||
async def test_core_store_no_country(
|
async def test_core_store_no_country(
|
||||||
hass: HomeAssistant, hass_storage: dict[str, Any], issue_registry: ir.IssueRegistry
|
hass: HomeAssistant, hass_storage: dict[str, Any], issue_registry: ir.IssueRegistry
|
||||||
) -> None:
|
) -> None:
|
||||||
@ -2511,3 +2483,30 @@ async def test_loading_platforms_gathers(hass: HomeAssistant) -> None:
|
|||||||
("platform_int", "sensor"),
|
("platform_int", "sensor"),
|
||||||
("platform_int2", "sensor"),
|
("platform_int2", "sensor"),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_configuration_legacy_template_is_removed(hass: HomeAssistant) -> None:
|
||||||
|
"""Test loading core config onto hass object."""
|
||||||
|
await config_util.async_process_ha_core_config(
|
||||||
|
hass,
|
||||||
|
{
|
||||||
|
"latitude": 60,
|
||||||
|
"longitude": 50,
|
||||||
|
"elevation": 25,
|
||||||
|
"name": "Huis",
|
||||||
|
"unit_system": "imperial",
|
||||||
|
"time_zone": "America/New_York",
|
||||||
|
"allowlist_external_dirs": "/etc",
|
||||||
|
"external_url": "https://www.example.com",
|
||||||
|
"internal_url": "http://example.local",
|
||||||
|
"media_dirs": {"mymedia": "/usr"},
|
||||||
|
"legacy_templates": True,
|
||||||
|
"debug": True,
|
||||||
|
"currency": "EUR",
|
||||||
|
"country": "SE",
|
||||||
|
"language": "sv",
|
||||||
|
"radius": 150,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert not getattr(hass.config, "legacy_templates")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user