mirror of
https://github.com/home-assistant/core
synced 2024-07-21 10:44:07 +00:00
Deprecate legacy_templates (#105556)
* Deprecate legacy_templates * Improve wording * Implement suggestion * simplify * Add deleting of the repair issues back * Update homeassistant/components/homeassistant/strings.json Co-authored-by: Martin Hjelmare <marhje52@gmail.com> * Test issue removal too --------- Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
88ea5f7a54
commit
8b08b5e8d2
|
@ -12,6 +12,14 @@
|
|||
"title": "The configured currency is no longer in use",
|
||||
"description": "The currency {currency} is no longer in use, please reconfigure the currency configuration."
|
||||
},
|
||||
"legacy_templates_false": {
|
||||
"title": "`legacy_templates` config key is being removed",
|
||||
"description": "Nothing will change with your templates.\n\nRemove the `legacy_templates` key from the `homeassistant` configuration in your configuration.yaml file and restart Home Assistant to fix this issue."
|
||||
},
|
||||
"legacy_templates_true": {
|
||||
"title": "The support for legacy templates is being removed",
|
||||
"description": "Please do the following steps:\n- Adopt your configuration to support template rendering to native python types.\n- Remove the `legacy_templates` key from the `homeassistant` configuration in your configuration.yaml file.\n- Restart Home Assistant to fix this issue."
|
||||
},
|
||||
"python_version": {
|
||||
"title": "Support for Python {current_python_version} is being removed",
|
||||
"description": "Support for running Home Assistant in the current used Python version {current_python_version} is deprecated and will be removed in Home Assistant {breaks_in_ha_version}. Please upgrade Python to {required_python_version} to prevent your Home Assistant instance from breaking."
|
||||
|
|
|
@ -272,6 +272,41 @@ 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,
|
||||
"homeassistant",
|
||||
"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, "homeassistant", "legacy_templates_true")
|
||||
|
||||
if legacy_templates is False:
|
||||
ir.async_create_issue(
|
||||
hass,
|
||||
"homeassistant",
|
||||
"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, "homeassistant", "legacy_templates_false")
|
||||
|
||||
|
||||
def _validate_currency(data: Any) -> Any:
|
||||
try:
|
||||
return cv.currency(data)
|
||||
|
@ -840,6 +875,7 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non
|
|||
if key in config:
|
||||
setattr(hac, attr, config[key])
|
||||
|
||||
_raise_issue_if_legacy_templates(hass, config.get(CONF_LEGACY_TEMPLATES))
|
||||
_raise_issue_if_historic_currency(hass, hass.config.currency)
|
||||
_raise_issue_if_no_country(hass, hass.config.country)
|
||||
|
||||
|
|
|
@ -1980,6 +1980,30 @@ async def test_core_config_schema_no_country(hass: HomeAssistant) -> None:
|
|||
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
|
||||
) -> None:
|
||||
"""Test legacy_template core config schema."""
|
||||
await config_util.async_process_ha_core_config(hass, config)
|
||||
|
||||
issue_registry = ir.async_get(hass)
|
||||
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(
|
||||
hass: HomeAssistant, hass_storage: dict[str, Any]
|
||||
) -> None:
|
||||
|
|
Loading…
Reference in a new issue