Do not fail MQTT setup if sirens configured via yaml can't be validated (#102319)
Add siren
This commit is contained in:
parent
d0341c9754
commit
1456809f6a
2 changed files with 11 additions and 22 deletions
|
@ -25,7 +25,6 @@ from . import (
|
||||||
number as number_platform,
|
number as number_platform,
|
||||||
select as select_platform,
|
select as select_platform,
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
siren as siren_platform,
|
|
||||||
switch as switch_platform,
|
switch as switch_platform,
|
||||||
text as text_platform,
|
text as text_platform,
|
||||||
update as update_platform,
|
update as update_platform,
|
||||||
|
@ -96,10 +95,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.SIREN.value: vol.All(
|
Platform.SIREN.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[siren_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.SWITCH.value: vol.All(
|
Platform.SWITCH.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[switch_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[switch_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
|
||||||
from typing import Any, cast
|
from typing import Any, cast
|
||||||
|
|
||||||
|
@ -32,7 +31,7 @@ import homeassistant.helpers.config_validation as cv
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.json import json_dumps
|
from homeassistant.helpers.json import json_dumps
|
||||||
from homeassistant.helpers.template import Template
|
from homeassistant.helpers.template import Template
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType, TemplateVarsType
|
from homeassistant.helpers.typing import ConfigType, TemplateVarsType
|
||||||
from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads_object
|
from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads_object
|
||||||
|
|
||||||
from . import subscription
|
from . import subscription
|
||||||
|
@ -52,7 +51,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 (
|
||||||
|
@ -122,21 +121,15 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT siren through YAML and through MQTT discovery."""
|
"""Set up MQTT siren 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,
|
||||||
|
MqttSiren,
|
||||||
|
siren.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, siren.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 siren."""
|
|
||||||
async_add_entities([MqttSiren(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttSiren(MqttEntity, SirenEntity):
|
class MqttSiren(MqttEntity, SirenEntity):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue