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