Do not fail MQTT setup if switches configured via yaml can't be validated (#102320)
Add switch
This commit is contained in:
parent
54c80491e3
commit
ec1b3fe6fb
2 changed files with 11 additions and 22 deletions
|
@ -23,7 +23,6 @@ from . import (
|
|||
lock as lock_platform,
|
||||
number as number_platform,
|
||||
sensor as sensor_platform,
|
||||
switch as switch_platform,
|
||||
update as update_platform,
|
||||
water_heater as water_heater_platform,
|
||||
)
|
||||
|
@ -86,10 +85,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
|||
[sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SIREN.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.SWITCH.value: vol.All(
|
||||
cv.ensure_list,
|
||||
[switch_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||
),
|
||||
Platform.SWITCH.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.TEXT.value: vol.All(cv.ensure_list, [dict]),
|
||||
Platform.UPDATE.value: vol.All(
|
||||
cv.ensure_list,
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Callable
|
||||
import functools
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -24,7 +23,7 @@ import homeassistant.helpers.config_validation as cv
|
|||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.restore_state import RestoreEntity
|
||||
from homeassistant.helpers.service_info.mqtt import ReceivePayloadType
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
|
||||
from . import subscription
|
||||
from .config import MQTT_RW_SCHEMA
|
||||
|
@ -40,7 +39,7 @@ from .debug_info import log_messages
|
|||
from .mixins import (
|
||||
MQTT_ENTITY_COMMON_SCHEMA,
|
||||
MqttEntity,
|
||||
async_setup_entry_helper,
|
||||
async_mqtt_entry_helper,
|
||||
write_state_on_attr_change,
|
||||
)
|
||||
from .models import MqttValueTemplate, ReceiveMessage
|
||||
|
@ -72,21 +71,15 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT switch 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,
|
||||
MqttSwitch,
|
||||
switch.DOMAIN,
|
||||
async_add_entities,
|
||||
DISCOVERY_SCHEMA,
|
||||
PLATFORM_SCHEMA_MODERN,
|
||||
)
|
||||
await async_setup_entry_helper(hass, switch.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 switch."""
|
||||
async_add_entities([MqttSwitch(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttSwitch(MqttEntity, SwitchEntity, RestoreEntity):
|
||||
|
|
Loading…
Add table
Reference in a new issue