2019-04-22 19:49:15 +00:00
|
|
|
"""The tests for the Legacy Mqtt vacuum platform."""
|
2023-07-11 07:54:28 +00:00
|
|
|
|
|
|
|
# The legacy schema for MQTT vacuum was deprecated with HA Core 2023.8.0
|
2024-01-08 08:22:43 +00:00
|
|
|
# and was removed with HA Core 2024.2.0
|
|
|
|
# cleanup is planned with HA Core 2025.2
|
2023-07-11 07:54:28 +00:00
|
|
|
|
2019-01-06 18:23:33 +00:00
|
|
|
import json
|
2017-09-15 13:39:20 +00:00
|
|
|
|
2020-05-06 21:14:57 +00:00
|
|
|
import pytest
|
|
|
|
|
2022-09-06 09:02:15 +00:00
|
|
|
from homeassistant.components import mqtt, vacuum
|
2023-02-08 17:08:03 +00:00
|
|
|
from homeassistant.core import HomeAssistant
|
2024-01-08 08:22:43 +00:00
|
|
|
from homeassistant.helpers.typing import DiscoveryInfoType
|
2020-03-09 16:40:00 +00:00
|
|
|
|
|
|
|
from tests.common import async_fire_mqtt_message
|
2024-01-08 08:22:43 +00:00
|
|
|
from tests.typing import MqttMockHAClientGenerator
|
2023-03-23 18:14:44 +00:00
|
|
|
|
2024-01-08 08:22:43 +00:00
|
|
|
DEFAULT_CONFIG = {mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}
|
2023-03-23 18:14:44 +00:00
|
|
|
|
2019-01-06 16:05:04 +00:00
|
|
|
|
2023-07-11 07:54:28 +00:00
|
|
|
@pytest.mark.parametrize(
|
2024-01-08 08:22:43 +00:00
|
|
|
("hass_config", "removed"),
|
2023-07-11 07:54:28 +00:00
|
|
|
[
|
|
|
|
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "legacy"}}}, True),
|
2024-01-08 08:22:43 +00:00
|
|
|
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test"}}}, False),
|
2024-07-03 19:35:20 +00:00
|
|
|
({mqtt.DOMAIN: {vacuum.DOMAIN: {"name": "test", "schema": "state"}}}, True),
|
2023-07-11 07:54:28 +00:00
|
|
|
],
|
|
|
|
)
|
2024-01-08 08:22:43 +00:00
|
|
|
async def test_removed_support_yaml(
|
2023-07-11 07:54:28 +00:00
|
|
|
hass: HomeAssistant,
|
|
|
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
|
|
|
caplog: pytest.LogCaptureFixture,
|
2024-01-08 08:22:43 +00:00
|
|
|
removed: bool,
|
2023-07-11 07:54:28 +00:00
|
|
|
) -> None:
|
2024-01-08 08:22:43 +00:00
|
|
|
"""Test that the removed support validation for the legacy schema works."""
|
2023-07-11 07:54:28 +00:00
|
|
|
assert await mqtt_mock_entry()
|
|
|
|
entity = hass.states.get("vacuum.test")
|
2023-07-11 08:16:00 +00:00
|
|
|
|
2024-01-08 08:22:43 +00:00
|
|
|
if removed:
|
|
|
|
assert entity is None
|
|
|
|
assert (
|
2024-07-03 19:35:20 +00:00
|
|
|
"The 'schema' option has been removed, "
|
|
|
|
"please remove it from your configuration" in caplog.text
|
2023-03-23 18:14:44 +00:00
|
|
|
)
|
2024-01-08 08:22:43 +00:00
|
|
|
else:
|
|
|
|
assert entity is not None
|
2019-01-06 16:05:04 +00:00
|
|
|
|
|
|
|
|
2023-03-23 18:14:44 +00:00
|
|
|
@pytest.mark.parametrize(
|
2024-01-08 08:22:43 +00:00
|
|
|
("config", "removed"),
|
2023-03-23 18:14:44 +00:00
|
|
|
[
|
2024-01-08 08:22:43 +00:00
|
|
|
({"name": "test", "schema": "legacy"}, True),
|
|
|
|
({"name": "test"}, False),
|
2024-07-03 19:35:20 +00:00
|
|
|
({"name": "test", "schema": "state"}, True),
|
2023-03-23 18:14:44 +00:00
|
|
|
],
|
|
|
|
)
|
2024-01-08 08:22:43 +00:00
|
|
|
async def test_removed_support_discovery(
|
2023-03-23 18:14:44 +00:00
|
|
|
hass: HomeAssistant,
|
2023-04-12 07:43:03 +00:00
|
|
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
2023-03-23 18:14:44 +00:00
|
|
|
caplog: pytest.LogCaptureFixture,
|
2024-01-08 08:22:43 +00:00
|
|
|
config: DiscoveryInfoType,
|
|
|
|
removed: bool,
|
2023-03-23 18:14:44 +00:00
|
|
|
) -> None:
|
2024-01-08 08:22:43 +00:00
|
|
|
"""Test that the removed support validation for the legacy schema works."""
|
2023-10-19 18:11:09 +00:00
|
|
|
assert await mqtt_mock_entry()
|
2019-04-14 03:29:01 +00:00
|
|
|
|
2024-01-08 08:22:43 +00:00
|
|
|
config_payload = json.dumps(config)
|
|
|
|
async_fire_mqtt_message(hass, "homeassistant/vacuum/test/config", config_payload)
|
|
|
|
await hass.async_block_till_done()
|
2023-09-25 20:17:29 +00:00
|
|
|
|
2024-01-08 08:22:43 +00:00
|
|
|
entity = hass.states.get("vacuum.test")
|
2024-07-03 19:35:20 +00:00
|
|
|
assert entity is not None
|
2023-09-25 20:17:29 +00:00
|
|
|
|
2024-01-08 08:22:43 +00:00
|
|
|
if removed:
|
|
|
|
assert (
|
2024-07-03 19:35:20 +00:00
|
|
|
"The 'schema' option has been removed, "
|
|
|
|
"please remove it from your configuration" in caplog.text
|
2023-09-25 20:17:29 +00:00
|
|
|
)
|
2024-01-08 08:22:43 +00:00
|
|
|
else:
|
2024-07-03 19:35:20 +00:00
|
|
|
assert (
|
|
|
|
"The 'schema' option has been removed, "
|
|
|
|
"please remove it from your configuration" not in caplog.text
|
|
|
|
)
|