From 2040c285b10c68afd214ea1eaec0b100863d9762 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Wed, 3 Jul 2024 21:35:20 +0200 Subject: [PATCH] Remove schema option for mqtt vacuum configs (#121093) --- homeassistant/components/mqtt/strings.json | 4 -- homeassistant/components/mqtt/vacuum.py | 66 ++++----------------- tests/components/mqtt/test_legacy_vacuum.py | 19 +++--- tests/components/mqtt/test_vacuum.py | 9 +-- 4 files changed, 25 insertions(+), 73 deletions(-) diff --git a/homeassistant/components/mqtt/strings.json b/homeassistant/components/mqtt/strings.json index 6034197aec7..f1e740d7f35 100644 --- a/homeassistant/components/mqtt/strings.json +++ b/homeassistant/components/mqtt/strings.json @@ -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." diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index 8aa42270016..c9898465184 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -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), ) diff --git a/tests/components/mqtt/test_legacy_vacuum.py b/tests/components/mqtt/test_legacy_vacuum.py index e4f5e3cd481..9b45b65d2cc 100644 --- a/tests/components/mqtt/test_legacy_vacuum.py +++ b/tests/components/mqtt/test_legacy_vacuum.py @@ -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 + ) diff --git a/tests/components/mqtt/test_vacuum.py b/tests/components/mqtt/test_vacuum.py index a7a5280c3e1..7fc4ff981fd 100644 --- a/tests/components/mqtt/test_vacuum.py +++ b/tests/components/mqtt/test_vacuum.py @@ -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])