mirror of
https://github.com/home-assistant/core.git
synced 2025-07-22 20:57:21 +00:00
Do not fail MQTT setup if text's configured via yaml can't be validated (#102322)
Add text
This commit is contained in:
parent
1456809f6a
commit
5eb0a33795
@ -26,7 +26,6 @@ from . import (
|
|||||||
select as select_platform,
|
select as select_platform,
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
switch as switch_platform,
|
switch as switch_platform,
|
||||||
text as text_platform,
|
|
||||||
update as update_platform,
|
update as update_platform,
|
||||||
vacuum as vacuum_platform,
|
vacuum as vacuum_platform,
|
||||||
water_heater as water_heater_platform,
|
water_heater as water_heater_platform,
|
||||||
@ -100,10 +99,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
|||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[switch_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[switch_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.TEXT.value: vol.All(
|
Platform.TEXT.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[text_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.UPDATE.value: vol.All(
|
Platform.UPDATE.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[update_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[update_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
@ -22,7 +21,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
|
|
||||||
from . import subscription
|
from . import subscription
|
||||||
from .config import MQTT_RW_SCHEMA
|
from .config import MQTT_RW_SCHEMA
|
||||||
@ -38,7 +37,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 (
|
from .models import (
|
||||||
@ -108,21 +107,15 @@ async def async_setup_entry(
|
|||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT text through YAML and through MQTT discovery."""
|
"""Set up MQTT text 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,
|
||||||
|
MqttTextEntity,
|
||||||
|
text.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, text.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 text."""
|
|
||||||
async_add_entities([MqttTextEntity(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttTextEntity(MqttEntity, TextEntity):
|
class MqttTextEntity(MqttEntity, TextEntity):
|
||||||
|
@ -205,11 +205,13 @@ async def test_controlling_validation_state_via_topic(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_attribute_validation_max_greater_then_min(
|
async def test_attribute_validation_max_greater_then_min(
|
||||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
hass: HomeAssistant,
|
||||||
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the validation of min and max configuration attributes."""
|
"""Test the validation of min and max configuration attributes."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
assert "not a valid value" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
@ -228,11 +230,13 @@ async def test_attribute_validation_max_greater_then_min(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
async def test_attribute_validation_max_not_greater_then_max_state_length(
|
async def test_attribute_validation_max_not_greater_then_max_state_length(
|
||||||
hass: HomeAssistant, mqtt_mock_entry: MqttMockHAClientGenerator
|
hass: HomeAssistant,
|
||||||
|
mqtt_mock_entry: MqttMockHAClientGenerator,
|
||||||
|
caplog: pytest.LogCaptureFixture,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test the max value of of max configuration attribute."""
|
"""Test the max value of of max configuration attribute."""
|
||||||
with pytest.raises(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
assert "not a valid value" in caplog.text
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user