Cleanup removed schema option from mqtt vacuum platform (#124722)

This commit is contained in:
Jan Bouwhuis 2024-08-28 07:49:05 +02:00 committed by GitHub
parent 9d3895d69a
commit e720a14dc4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 3 additions and 137 deletions

View File

@ -1,10 +1,5 @@
"""Support for MQTT vacuums."""
# The legacy schema for MQTT vacuum was deprecated with HA Core 2023.8.0
# and was removed with HA Core 2024.2.0
# The use of the schema attribute with MQTT vacuum was deprecated with HA Core 2024.2
# the attribute will be remove with HA Core 2024.8
from __future__ import annotations
import logging
@ -38,15 +33,12 @@ 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
from .const import CONF_COMMAND_TOPIC, CONF_RETAIN, CONF_STATE_TOPIC
from .mixins import MqttEntity, async_setup_entity_entry_helper
from .models import ReceiveMessage
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import valid_publish_topic
LEGACY = "legacy"
STATE = "state"
BATTERY = "battery_level"
FAN_SPEED = "fan_speed"
STATE = "state"
@ -149,7 +141,7 @@ MQTT_VACUUM_ATTRIBUTES_BLOCKED = frozenset(
MQTT_VACUUM_DOCS_URL = "https://www.home-assistant.io/integrations/vacuum.mqtt/"
VACUUM_BASE_SCHEMA = MQTT_BASE_SCHEMA.extend(
PLATFORM_SCHEMA_MODERN = MQTT_BASE_SCHEMA.extend(
{
vol.Optional(CONF_FAN_SPEED_LIST, default=[]): vol.All(
cv.ensure_list, [cv.string]
@ -173,26 +165,10 @@ VACUUM_BASE_SCHEMA = MQTT_BASE_SCHEMA.extend(
),
vol.Optional(CONF_COMMAND_TOPIC): valid_publish_topic,
vol.Optional(CONF_RETAIN, default=DEFAULT_RETAIN): cv.boolean,
vol.Optional(CONF_SCHEMA): vol.All(vol.Lower, vol.Any(LEGACY, STATE)),
}
).extend(MQTT_ENTITY_COMMON_SCHEMA.schema)
DISCOVERY_SCHEMA = vol.All(
VACUUM_BASE_SCHEMA.extend({}, extra=vol.ALLOW_EXTRA),
# 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(
VACUUM_BASE_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),
)
DISCOVERY_SCHEMA = PLATFORM_SCHEMA_MODERN.extend({}, extra=vol.ALLOW_EXTRA)
async def async_setup_entry(

View File

@ -1,83 +0,0 @@
"""The tests for the Legacy Mqtt vacuum platform."""
# The legacy schema for MQTT vacuum was deprecated with HA Core 2023.8.0
# and was removed with HA Core 2024.2.0
# cleanup is planned with HA Core 2025.2
import json
import pytest
from homeassistant.components import mqtt, vacuum
from homeassistant.core import HomeAssistant
from homeassistant.helpers.typing import DiscoveryInfoType
from tests.common import async_fire_mqtt_message
from tests.typing import MqttMockHAClientGenerator
DEFAULT_CONFIG = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
@pytest.mark.parametrize(
("hass_config", "removed"),
[
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "legacy"}}}, True),
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}, False),
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "state"}}}, True),
],
)
async def test_removed_support_yaml(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
removed: bool,
) -> None:
"""Test that the removed support validation for the legacy schema works."""
assert await mqtt_mock_entry()
entity = hass.states.get("vacuum.test")
if removed:
assert entity is None
assert (
"The 'schema' option has been removed, "
"please remove it from your configuration" in caplog.text
)
else:
assert entity is not None
@pytest.mark.parametrize(
("config", "removed"),
[
({"name": "test", "schema": "legacy"}, True),
({"name": "test"}, False),
({"name": "test", "schema": "state"}, True),
],
)
async def test_removed_support_discovery(
hass: HomeAssistant,
mqtt_mock_entry: MqttMockHAClientGenerator,
caplog: pytest.LogCaptureFixture,
config: DiscoveryInfoType,
removed: bool,
) -> None:
"""Test that the removed support validation for the legacy schema works."""
assert await mqtt_mock_entry()
config_payload = json.dumps(config)
async_fire_mqtt_message(hass, "homeassistant/vacuum/test/config", config_payload)
await hass.async_block_till_done()
entity = hass.states.get("vacuum.test")
assert entity is not None
if removed:
assert (
"The 'schema' option has been removed, "
"please remove it from your configuration" in caplog.text
)
else:
assert (
"The 'schema' option has been removed, "
"please remove it from your configuration" not in caplog.text
)

View File

@ -2,7 +2,6 @@
from copy import deepcopy
import json
import logging
from typing import Any
from unittest.mock import patch
@ -102,32 +101,6 @@ 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")
# 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 has been removed, "
"please remove it from your configuration" in caplog.text
)
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
async def test_default_supported_features(
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator