mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 05:07:41 +00:00
Do not fail MQTT setup if buttons configured via yaml can't be validated (#102301)
This commit is contained in:
parent
bb90c1f168
commit
04fdcbe5fa
@ -1,8 +1,6 @@
|
||||
"""Support for MQTT buttons."""
|
||||
from __future__ import annotations
|
||||
|
||||
import functools
|
||||
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components import button
|
||||
@ -12,7 +10,7 @@ from homeassistant.const import CONF_DEVICE_CLASS, CONF_NAME
|
||||
from homeassistant.core import HomeAssistant
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from .config import DEFAULT_RETAIN, MQTT_BASE_SCHEMA
|
||||
from .const import (
|
||||
@ -22,7 +20,7 @@ from .const import (
|
||||
CONF_QOS,
|
||||
CONF_RETAIN,
|
||||
)
|
||||
from .mixins import MQTT_ENTITY_COMMON_SCHEMA, MqttEntity, async_setup_entry_helper
|
||||
from .mixins import MQTT_ENTITY_COMMON_SCHEMA, MqttEntity, async_mqtt_entry_helper
|
||||
from .models import MqttCommandTemplate
|
||||
from .util import valid_publish_topic
|
||||
|
||||
@ -50,21 +48,15 @@ async def async_setup_entry(
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT button through YAML and through MQTT discovery."""
|
||||
setup = functools.partial(
|
||||
_async_setup_entity, hass, async_add_entities, config_entry=config_entry
|
||||
await async_mqtt_entry_helper(
|
||||
hass,
|
||||
config_entry,
|
||||
MqttButton,
|
||||
button.DOMAIN,
|
||||
async_add_entities,
|
||||
DISCOVERY_SCHEMA,
|
||||
PLATFORM_SCHEMA_MODERN,
|
||||
)
|
||||
await async_setup_entry_helper(hass, button.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 button."""
|
||||
async_add_entities([MqttButton(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttButton(MqttEntity, ButtonEntity):
|
||||
|
@ -15,7 +15,6 @@ from homeassistant.const import (
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
|
||||
from . import (
|
||||
button as button_platform,
|
||||
cover as cover_platform,
|
||||
event as event_platform,
|
||||
number as number_platform,
|
||||
@ -41,10 +40,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||
{
|
||||
Platform.ALARM_CONTROL_PANEL.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.BINARY_SENSOR.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.BUTTON.value: vol.All(
|
||||
cv.ensure_list,
|
||||
[button_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.BUTTON.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.COVER.value: vol.All(
|
||||
|
@ -456,8 +456,7 @@ async def test_invalid_device_class(
|
||||
caplog: pytest.LogCaptureFixture,
|
||||
) -> None:
|
||||
"""Test device_class option with invalid value."""
|
||||
with pytest.raises(AssertionError):
|
||||
await mqtt_mock_entry()
|
||||
assert await mqtt_mock_entry()
|
||||
assert "expected ButtonDeviceClass" in caplog.text
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user