mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Do not fail MQTT setup if covers configured via yaml can't be validated (#102304)
Add cover
This commit is contained in:
parent
12c4a10cfc
commit
1efbba2631
@ -15,7 +15,6 @@ from homeassistant.const import (
|
|||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
cover as cover_platform,
|
|
||||||
event as event_platform,
|
event as event_platform,
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
)
|
)
|
||||||
@ -40,10 +39,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
|||||||
Platform.BUTTON.value: vol.All(cv.ensure_list, [dict]),
|
Platform.BUTTON.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.CAMERA.value: vol.All(cv.ensure_list, [dict]),
|
Platform.CAMERA.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.CLIMATE.value: vol.All(cv.ensure_list, [dict]),
|
Platform.CLIMATE.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.COVER.value: vol.All(
|
Platform.COVER.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[cover_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.DEVICE_TRACKER.value: vol.All(cv.ensure_list, [dict]),
|
Platform.DEVICE_TRACKER.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.EVENT.value: vol.All(
|
Platform.EVENT.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
@ -31,7 +30,7 @@ from homeassistant.core import HomeAssistant, callback
|
|||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.service_info.mqtt import ReceivePayloadType
|
from homeassistant.helpers.service_info.mqtt import ReceivePayloadType
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
||||||
|
|
||||||
from . import subscription
|
from . import subscription
|
||||||
@ -48,7 +47,7 @@ from .debug_info import log_messages
|
|||||||
from .mixins import (
|
from .mixins import (
|
||||||
MQTT_ENTITY_COMMON_SCHEMA,
|
MQTT_ENTITY_COMMON_SCHEMA,
|
||||||
MqttEntity,
|
MqttEntity,
|
||||||
async_setup_entry_helper,
|
async_mqtt_entry_helper,
|
||||||
write_state_on_attr_change,
|
write_state_on_attr_change,
|
||||||
)
|
)
|
||||||
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
|
from .models import MqttCommandTemplate, MqttValueTemplate, ReceiveMessage
|
||||||
@ -220,21 +219,15 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT cover through YAML and through MQTT discovery."""
|
"""Set up MQTT cover through YAML and through MQTT discovery."""
|
||||||
setup = functools.partial(
|
await async_mqtt_entry_helper(
|
||||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
hass,
|
||||||
|
config_entry,
|
||||||
|
MqttCover,
|
||||||
|
cover.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, cover.DOMAIN, setup, DISCOVERY_SCHEMA)
|
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup_entity(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
config: ConfigType,
|
|
||||||
config_entry: ConfigEntry,
|
|
||||||
discovery_data: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the MQTT Cover."""
|
|
||||||
async_add_entities([MqttCover(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttCover(MqttEntity, CoverEntity):
|
class MqttCover(MqttEntity, CoverEntity):
|
||||||
|
@ -891,11 +891,9 @@ async def test_optimistic_position(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test optimistic position is not supported."""
|
"""Test optimistic position is not supported."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
"Invalid config for [mqtt]: 'set_position_topic' must be set together with 'position_topic'"
|
"'set_position_topic' must be set together with 'position_topic'" in caplog.text
|
||||||
in caplog.text
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -2663,9 +2661,8 @@ async def test_invalid_device_class(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the setting of an invalid device class."""
|
"""Test the setting of an invalid device class."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
assert "expected CoverDeviceClass" in caplog.text
|
||||||
assert "Invalid config for [mqtt]: expected CoverDeviceClass" in caplog.text
|
|
||||||
|
|
||||||
|
|
||||||
async def test_setting_attribute_via_mqtt_json_message(
|
async def test_setting_attribute_via_mqtt_json_message(
|
||||||
@ -3402,8 +3399,7 @@ async def test_set_position_topic_without_get_position_topic_error(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when set_position_topic is used without position_topic."""
|
"""Test error when set_position_topic is used without position_topic."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_SET_POSITION_TOPIC}' must be set together with '{CONF_GET_POSITION_TOPIC}'."
|
f"'{CONF_SET_POSITION_TOPIC}' must be set together with '{CONF_GET_POSITION_TOPIC}'."
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
@ -3429,8 +3425,7 @@ async def test_value_template_without_state_topic_error(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when value_template is used and state_topic is missing."""
|
"""Test error when value_template is used and state_topic is missing."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_VALUE_TEMPLATE}' must be set together with '{CONF_STATE_TOPIC}'."
|
f"'{CONF_VALUE_TEMPLATE}' must be set together with '{CONF_STATE_TOPIC}'."
|
||||||
) in caplog.text
|
) in caplog.text
|
||||||
@ -3456,8 +3451,7 @@ async def test_position_template_without_position_topic_error(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when position_template is used and position_topic is missing."""
|
"""Test error when position_template is used and position_topic is missing."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_GET_POSITION_TEMPLATE}' must be set together with '{CONF_GET_POSITION_TOPIC}'."
|
f"'{CONF_GET_POSITION_TEMPLATE}' must be set together with '{CONF_GET_POSITION_TOPIC}'."
|
||||||
in caplog.text
|
in caplog.text
|
||||||
@ -3484,8 +3478,7 @@ async def test_set_position_template_without_set_position_topic(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when set_position_template is used and set_position_topic is missing."""
|
"""Test error when set_position_template is used and set_position_topic is missing."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_SET_POSITION_TEMPLATE}' must be set together with '{CONF_SET_POSITION_TOPIC}'."
|
f"'{CONF_SET_POSITION_TEMPLATE}' must be set together with '{CONF_SET_POSITION_TOPIC}'."
|
||||||
in caplog.text
|
in caplog.text
|
||||||
@ -3512,8 +3505,7 @@ async def test_tilt_command_template_without_tilt_command_topic(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when tilt_command_template is used and tilt_command_topic is missing."""
|
"""Test error when tilt_command_template is used and tilt_command_topic is missing."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_TILT_COMMAND_TEMPLATE}' must be set together with '{CONF_TILT_COMMAND_TOPIC}'."
|
f"'{CONF_TILT_COMMAND_TEMPLATE}' must be set together with '{CONF_TILT_COMMAND_TOPIC}'."
|
||||||
in caplog.text
|
in caplog.text
|
||||||
@ -3540,8 +3532,7 @@ async def test_tilt_status_template_without_tilt_status_topic_topic(
|
|||||||
mqtt_mock_entry: MqttMockHAClientGenerator,
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test error when tilt_status_template is used and tilt_status_topic is missing."""
|
"""Test error when tilt_status_template is used and tilt_status_topic is missing."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert (
|
assert (
|
||||||
f"'{CONF_TILT_STATUS_TEMPLATE}' must be set together with '{CONF_TILT_STATUS_TOPIC}'."
|
f"'{CONF_TILT_STATUS_TEMPLATE}' must be set together with '{CONF_TILT_STATUS_TOPIC}'."
|
||||||
in caplog.text
|
in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user