Do not fail MQTT setup if select's configured via yaml can't be validated (#102318)
Add select
This commit is contained in:
parent
e6e2aa0ea0
commit
54c80491e3
2 changed files with 11 additions and 22 deletions
|
@ -22,7 +22,6 @@ from . import (
|
||||||
lawn_mower as lawn_mower_platform,
|
lawn_mower as lawn_mower_platform,
|
||||||
lock as lock_platform,
|
lock as lock_platform,
|
||||||
number as number_platform,
|
number as number_platform,
|
||||||
select as select_platform,
|
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
switch as switch_platform,
|
switch as switch_platform,
|
||||||
update as update_platform,
|
update as update_platform,
|
||||||
|
@ -81,10 +80,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.SCENE.value: vol.All(cv.ensure_list, [dict]),
|
Platform.SCENE.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.SELECT.value: vol.All(
|
Platform.SELECT.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[select_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.SENSOR.value: vol.All(
|
Platform.SENSOR.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[sensor_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[sensor_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 voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -15,7 +14,7 @@ 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.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
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
|
||||||
|
@ -31,7 +30,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 (
|
||||||
|
@ -73,21 +72,15 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT select through YAML and through MQTT discovery."""
|
"""Set up MQTT select 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,
|
||||||
|
MqttSelect,
|
||||||
|
select.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, select.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 select."""
|
|
||||||
async_add_entities([MqttSelect(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
class MqttSelect(MqttEntity, SelectEntity, RestoreEntity):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue