Remove schema option for mqtt vacuum configs (#121093)

This commit is contained in:
Jan Bouwhuis 2024-07-03 21:35:20 +02:00 committed by GitHub
parent 53767b6159
commit 2040c285b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 25 additions and 73 deletions

View File

@ -1,9 +1,5 @@
{
"issues": {
"deprecation_mqtt_schema_vacuum_yaml": {
"title": "MQTT vacuum entities with deprecated `schema` config settings found in your configuration.yaml",
"description": "The `schema` setting for MQTT vacuum entities is deprecated and should be removed. Please adjust your configuration.yaml and restart Home Assistant to fix this issue."
},
"deprecated_color_handling": {
"title": "Deprecated color handling used for MQTT light",
"description": "An MQTT light config (with `json` schema) found in `configuration.yaml` uses deprecated color handling flags.\n\nConfiguration found:\n```yaml\n{config}\n```\nDeprecated flags: **{deprecated_flags}**.\n\nUse the `supported_color_modes` option instead and [reload](/developer-tools/yaml) the manually configured MQTT items or restart Home Assistant to fix this issue."

View File

@ -7,7 +7,6 @@
from __future__ import annotations
from collections.abc import Callable
import logging
from typing import Any, cast
@ -30,23 +29,16 @@ from homeassistant.const import (
STATE_IDLE,
STATE_PAUSED,
)
from homeassistant.core import HomeAssistant, async_get_hass, callback
from homeassistant.core import HomeAssistant, callback
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.entity_platform import AddEntitiesCallback
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
from homeassistant.helpers.json import json_dumps
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, VolSchemaType
from homeassistant.util.json import json_loads_object
from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import (
CONF_COMMAND_TOPIC,
CONF_RETAIN,
CONF_SCHEMA,
CONF_STATE_TOPIC,
DOMAIN,
)
from .const import CONF_COMMAND_TOPIC, CONF_RETAIN, CONF_SCHEMA, CONF_STATE_TOPIC
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .models import ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
@ -157,47 +149,6 @@ MQTT_VACUUM_ATTRIBUTES_BLOCKED = frozenset(
MQTT_VACUUM_DOCS_URL = "https://www.home-assistant.io/integrations/vacuum.mqtt/"
def _fail_legacy_config(discovery: bool) -> Callable[[ConfigType], ConfigType]:
@callback
def _fail_legacy_config_callback(config: ConfigType) -> ConfigType:
"""Fail the legacy schema."""
if CONF_SCHEMA not in config:
return config
if config[CONF_SCHEMA] == "legacy":
raise vol.Invalid(
"The support for the `legacy` MQTT vacuum schema has been removed"
)
if discovery:
_LOGGER.warning(
"The `schema` option is deprecated for MQTT %s, but "
"it was used in a discovery payload. Please contact the maintainer "
"of the integration or service that supplies the config, and suggest "
"to remove the option. Got %s at discovery topic %s",
vacuum.DOMAIN,
config,
getattr(config, "discovery_data")["discovery_topic"],
)
return config
translation_key = "deprecation_mqtt_schema_vacuum_yaml"
hass = async_get_hass()
async_create_issue(
hass,
DOMAIN,
translation_key,
breaks_in_ha_version="2024.8.0",
is_fixable=False,
translation_key=translation_key,
learn_more_url=MQTT_VACUUM_DOCS_URL,
severity=IssueSeverity.WARNING,
)
return config
return _fail_legacy_config_callback
VACUUM_BASE_SCHEMA = MQTT_BASE_SCHEMA.extend(
{
vol.Optional(CONF_FAN_SPEED_LIST, default=[]): vol.All(
@ -227,15 +178,20 @@ VACUUM_BASE_SCHEMA = MQTT_BASE_SCHEMA.extend(
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
DISCOVERY_SCHEMA = vol.All(
_fail_legacy_config(discovery=True),
VACUUM_BASE_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA),
cv.deprecated(CONF_SCHEMA),
# Do not fail a config is the schema option is still present,
# De option was deprecated with HA Core 2024.2 and removed with HA Core 2024.8.
# As we allow extra options, and we will remove this check silently
# with HA Core 2025.8.0, we will only warn,
# if a adiscovery config still uses this option.
cv.removed(CONF_SCHEMA, raise_if_present=False),
)
PLATFORM_SCHEMA_MODERN = vol.All(
_fail_legacy_config(discovery=False),
VACUUM_BASE_SCHEMA,
cv.deprecated(CONF_SCHEMA),
# The schema options was removed with HA Core 2024.8,
# the cleanup is planned for HA Core 2025.8.
cv.removed(CONF_SCHEMA, raise_if_present=True),
)

View File

@ -23,7 +23,7 @@ DEFAULT_CONFIG = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
[
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "legacy"}}}, True),
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}, False),
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "state"}}}, False),
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "state"}}}, True),
],
)
async def test_removed_support_yaml(
@ -39,8 +39,8 @@ async def test_removed_support_yaml(
if removed:
assert entity is None
assert (
"The support for the `legacy` MQTT "
"vacuum schema has been removed" in caplog.text
"The 'schema' option has been removed, "
"please remove it from your configuration" in caplog.text
)
else:
assert entity is not None
@ -51,7 +51,7 @@ async def test_removed_support_yaml(
[
({"name": "test", "schema": "legacy"}, True),
({"name": "test"}, False),
({"name": "test", "schema": "state"}, False),
({"name": "test", "schema": "state"}, True),
],
)
async def test_removed_support_discovery(
@ -69,12 +69,15 @@ async def test_removed_support_discovery(
await hass.async_block_till_done()
entity = hass.states.get("vacuum.test")
assert entity is not None
if removed:
assert entity is None
assert (
"The support for the `legacy` MQTT "
"vacuum schema has been removed" in caplog.text
"The 'schema' option has been removed, "
"please remove it from your configuration" in caplog.text
)
else:
assert entity is not None
assert (
"The 'schema' option has been removed, "
"please remove it from your configuration" not in caplog.text
)

View File

@ -119,16 +119,13 @@ async def test_warning_schema_option(
await hass.async_block_till_done(wait_background_tasks=True)
state = hass.states.get("vacuum.test")
# We do not fail if the schema option is still in the payload, but we log an error
assert state is not None
with caplog.at_level(logging.WARNING):
assert (
"The `schema` option is deprecated for MQTT vacuum, but it was used in a "
"discovery payload. Please contact the maintainer of the integration or "
"service that supplies the config, and suggest to remove the option."
in caplog.text
"The 'schema' option has been removed, "
"please remove it from your configuration" in caplog.text
)
assert "https://example.com/support" in caplog.text
assert "at discovery topic homeassistant/vacuum/bla/config" in caplog.text
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])