mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 08:47:10 +00:00
Improve logging use of deprecated schema
option for mqtt vacuum (#119724)
This commit is contained in:
parent
af0f540dd4
commit
b405e2f03e
@ -170,6 +170,15 @@ def _fail_legacy_config(discovery: bool) -> Callable[[ConfigType], ConfigType]:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if discovery:
|
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
|
return config
|
||||||
|
|
||||||
translation_key = "deprecation_mqtt_schema_vacuum_yaml"
|
translation_key = "deprecation_mqtt_schema_vacuum_yaml"
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
from unittest.mock import patch
|
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.const import CONF_COMMAND_TOPIC, CONF_STATE_TOPIC
|
||||||
from homeassistant.components.mqtt.vacuum import (
|
from homeassistant.components.mqtt.vacuum import (
|
||||||
ALL_SERVICES,
|
ALL_SERVICES,
|
||||||
CONF_SCHEMA,
|
|
||||||
MQTT_VACUUM_ATTRIBUTES_BLOCKED,
|
MQTT_VACUUM_ATTRIBUTES_BLOCKED,
|
||||||
SERVICE_TO_STRING,
|
SERVICE_TO_STRING,
|
||||||
services_to_strings,
|
services_to_strings,
|
||||||
@ -77,7 +77,6 @@ STATE_TOPIC = "vacuum/state"
|
|||||||
DEFAULT_CONFIG = {
|
DEFAULT_CONFIG = {
|
||||||
mqtt.DOMAIN: {
|
mqtt.DOMAIN: {
|
||||||
vacuum.DOMAIN: {
|
vacuum.DOMAIN: {
|
||||||
CONF_SCHEMA: "state",
|
|
||||||
CONF_NAME: "mqtttest",
|
CONF_NAME: "mqtttest",
|
||||||
CONF_COMMAND_TOPIC: COMMAND_TOPIC,
|
CONF_COMMAND_TOPIC: COMMAND_TOPIC,
|
||||||
mqttvacuum.CONF_SEND_COMMAND_TOPIC: SEND_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(
|
CONFIG_ALL_SERVICES = help_custom_config(
|
||||||
vacuum.DOMAIN,
|
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])
|
@pytest.mark.parametrize("hass_config", [DEFAULT_CONFIG])
|
||||||
async def test_default_supported_features(
|
async def test_default_supported_features(
|
||||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
||||||
@ -261,7 +289,6 @@ async def test_commands_without_supported_features(
|
|||||||
"mqtt": {
|
"mqtt": {
|
||||||
"vacuum": {
|
"vacuum": {
|
||||||
"name": "test",
|
"name": "test",
|
||||||
"schema": "state",
|
|
||||||
mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings(
|
mqttvacuum.CONF_SUPPORTED_FEATURES: services_to_strings(
|
||||||
ALL_SERVICES, SERVICE_TO_STRING
|
ALL_SERVICES, SERVICE_TO_STRING
|
||||||
),
|
),
|
||||||
@ -525,13 +552,11 @@ async def test_discovery_update_attr(
|
|||||||
mqtt.DOMAIN: {
|
mqtt.DOMAIN: {
|
||||||
vacuum.DOMAIN: [
|
vacuum.DOMAIN: [
|
||||||
{
|
{
|
||||||
"schema": "state",
|
|
||||||
"name": "Test 1",
|
"name": "Test 1",
|
||||||
"command_topic": "command-topic",
|
"command_topic": "command-topic",
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"schema": "state",
|
|
||||||
"name": "Test 2",
|
"name": "Test 2",
|
||||||
"command_topic": "command-topic",
|
"command_topic": "command-topic",
|
||||||
"unique_id": "TOTALLY_UNIQUE",
|
"unique_id": "TOTALLY_UNIQUE",
|
||||||
@ -554,7 +579,7 @@ async def test_discovery_removal_vacuum(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test removal of discovered vacuum."""
|
"""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(
|
await help_test_discovery_removal(
|
||||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
|
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data
|
||||||
)
|
)
|
||||||
@ -566,8 +591,8 @@ async def test_discovery_update_vacuum(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update of discovered vacuum."""
|
"""Test update of discovered vacuum."""
|
||||||
config1 = {"schema": "state", "name": "Beer", "command_topic": "test_topic"}
|
config1 = {"name": "Beer", "command_topic": "test_topic"}
|
||||||
config2 = {"schema": "state", "name": "Milk", "command_topic": "test_topic"}
|
config2 = {"name": "Milk", "command_topic": "test_topic"}
|
||||||
await help_test_discovery_update(
|
await help_test_discovery_update(
|
||||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2
|
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, config1, config2
|
||||||
)
|
)
|
||||||
@ -579,7 +604,7 @@ async def test_discovery_update_unchanged_vacuum(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test update of discovered vacuum."""
|
"""Test update of discovered vacuum."""
|
||||||
data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic"}'
|
data1 = '{"name": "Beer", "command_topic": "test_topic"}'
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.mqtt.vacuum.MqttStateVacuum.discovery_update"
|
"homeassistant.components.mqtt.vacuum.MqttStateVacuum.discovery_update"
|
||||||
) as discovery_update:
|
) as discovery_update:
|
||||||
@ -600,8 +625,8 @@ async def test_discovery_broken(
|
|||||||
caplog: pytest.LogCaptureFixture,
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test handling of bad discovery message."""
|
"""Test handling of bad discovery message."""
|
||||||
data1 = '{ "schema": "state", "name": "Beer", "command_topic": "test_topic#"}'
|
data1 = '{"name": "Beer", "command_topic": "test_topic#"}'
|
||||||
data2 = '{ "schema": "state", "name": "Milk", "command_topic": "test_topic"}'
|
data2 = '{"name": "Milk", "command_topic": "test_topic"}'
|
||||||
await help_test_discovery_broken(
|
await help_test_discovery_broken(
|
||||||
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2
|
hass, mqtt_mock_entry, caplog, vacuum.DOMAIN, data1, data2
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user