Do not fail MQTT setup if scenes configured via yaml can't be validated (#102317)
Add scene
This commit is contained in:
parent
c266583bea
commit
615b02be59
2 changed files with 11 additions and 22 deletions
|
@ -25,7 +25,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,
|
||||||
scene as scene_platform,
|
|
||||||
select as select_platform,
|
select as select_platform,
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
siren as siren_platform,
|
siren as siren_platform,
|
||||||
|
@ -96,10 +95,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.SCENE.value: vol.All(
|
Platform.SCENE.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[scene_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.SELECT.value: vol.All(
|
Platform.SELECT.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[select_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[select_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Support for MQTT scenes."""
|
"""Support for MQTT scenes."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
@ -13,11 +12,11 @@ from homeassistant.const import CONF_NAME, CONF_PAYLOAD_ON
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
import homeassistant.helpers.config_validation as cv
|
import homeassistant.helpers.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 .config import MQTT_BASE_SCHEMA
|
from .config import MQTT_BASE_SCHEMA
|
||||||
from .const import CONF_COMMAND_TOPIC, CONF_ENCODING, CONF_QOS, CONF_RETAIN
|
from .const import CONF_COMMAND_TOPIC, CONF_ENCODING, 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 .util import valid_publish_topic
|
from .util import valid_publish_topic
|
||||||
|
|
||||||
DEFAULT_NAME = "MQTT Scene"
|
DEFAULT_NAME = "MQTT Scene"
|
||||||
|
@ -43,21 +42,15 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT scene through YAML and through MQTT discovery."""
|
"""Set up MQTT scene 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,
|
||||||
|
MqttScene,
|
||||||
|
scene.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, scene.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 scene."""
|
|
||||||
async_add_entities([MqttScene(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttScene(
|
class MqttScene(
|
||||||
|
|
Loading…
Add table
Reference in a new issue