diff --git a/homeassistant/components/mqtt/vacuum.py b/homeassistant/components/mqtt/vacuum.py index fb988751d6b..eac3556a28b 100644 --- a/homeassistant/components/mqtt/vacuum.py +++ b/homeassistant/components/mqtt/vacuum.py @@ -170,6 +170,15 @@ def _fail_legacy_config(discovery: bool) -> Callable[[ConfigType], ConfigType]: ) 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" diff --git a/tests/components/mqtt/test_vacuum.py b/tests/components/mqtt/test_vacuum.py index 7563752b2d7..0a06759c7e6 100644 --- a/tests/components/mqtt/test_vacuum.py +++ b/tests/components/mqtt/test_vacuum.py @@ -2,6 +2,7 @@ from copy import deepcopy import json +import logging from typing import Any from unittest.mock import patch @@ -12,7 +13,6 @@ from homeassistant.components.mqtt import vacuum as mqttvacuum from homeassistant.components.mqtt.const import CONF_COMMAND_TOPIC, CONF_STATE_TOPIC from homeassistant.components.mqtt.vacuum import ( ALL_SERVICES, - CONF_SCHEMA, MQTT_VACUUM_ATTRIBUTES_BLOCKED, SERVICE_TO_STRING, services_to_strings, @@ -77,7 +77,6 @@ STATE_TOPIC = "vacuum/state" DEFAULT_CONFIG = { mqtt.DOMAIN: { vacuum.DOMAIN: { - CONF_SCHEMA: "state", CONF_NAME: "mqtttest", CONF_COMMAND_TOPIC: COMMAND_TOPIC, mqttvacuum.CONF_SEND_COMMAND_TOPIC: SEND_COMMAND_TOPIC, @@ -88,7 +87,7 @@ DEFAULT_CONFIG = { } } -DEFAULT_CONFIG_2 = {mqtt.DOMAIN: {vacuum.DOMAIN: {"schema": "state", "name": "test"}}} +DEFAULT_CONFIG_2 = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}} CONFIG_ALL_SERVICES = help_custom_config( vacuum.DOMAIN, @@ -103,6 +102,35 @@ CONFIG_ALL_SERVICES = help_custom_config( ) +async def test_warning_schema_option( + hass: HomeAssistant, + mqtt_mock_entry: MqttMockHAClientGenerator, + caplog: pytest.LogCaptureFixture, +) -> None: + """Test the warning on use of deprecated schema option.""" + await mqtt_mock_entry() + # Send discovery message with deprecated schema option + async_fire_mqtt_message( + hass, + f"homeassistant/{vacuum.DOMAIN}/bla/config", + '{"name": "test", "schema": "state", "o": {"name": "Bla2MQTT", "sw": "0.99", "url":"https://example.com/support"}}', + ) + await hass.async_block_till_done() + await hass.async_block_till_done(wait_background_tasks=True) + + state = hass.states.get("vacuum.test") + 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 + ) + 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]) async def test_default_supported_features( hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator @@ -261,7 +289,6 @@ async def test_commands_without_supported_features( "mqtt": { "vacuum": { "name": "test", - "schema": "state", mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings( ALL_SERVICES, SERVICE_TO_STRING ), @@ -525,13 +552,11 @@ async def test_discovery_update_attr( mqtt.DOMAIN: { vacuum.DOMAIN: [ { - "schema": "state", "name": "Test 1", "command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE", }, { - "schema": "state", "name": "Test 2", "command_topic": "command-topic", "unique_id": "TOTALLY_UNIQUE", @@ -554,7 +579,7 @@ async def test_discovery_removal_vacuum( caplog: pytest.LogCaptureFixture, ) -> None: """Test removal of discovered vacuum.""" - data = '{ "schema": "state", "name": "test", "command_topic": "test_topic"}' + data = '{"name": "test", "command_topic": "test_topic"}' await help_test_discovery_removal( hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data ) @@ -566,8 +591,8 @@ async def test_discovery_update_vacuum( caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" - config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"} - config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"} + config1 = {"name": "Beer", "command_topic": "test_topic"} + config2 = {"name": "Milk", "command_topic": "test_topic"} await help_test_discovery_update( hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2 ) @@ -579,7 +604,7 @@ async def test_discovery_update_unchanged_vacuum( caplog: pytest.LogCaptureFixture, ) -> None: """Test update of discovered vacuum.""" - data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic"}' + data1 = '{"name": "Beer", "command_topic": "test_topic"}' with patch( "homeassistant.components.mqtt.vacuum.MqttStateVacuum.discovery_update" ) as discovery_update: @@ -600,8 +625,8 @@ async def test_discovery_broken( caplog: pytest.LogCaptureFixture, ) -> None: """Test handling of bad discovery message.""" - data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}' - data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}' + data1 = '{"name": "Beer", "command_topic": "test_topic#"}' + data2 = '{"name": "Milk", "command_topic": "test_topic"}' await help_test_discovery_broken( hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2 )