Do not fail MQTT setup if scenes configured via yaml can't be validated (#102317)

Add scene
This commit is contained in:
Jan Bouwhuis 2023-10-19 18:27:04 +02:00 committed by GitHub
parent c266583bea
commit 615b02be59
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 22 deletions

View file

@ -25,7 +25,6 @@ from . import (
lawn_mower as lawn_mower_platform,
lock as lock_platform,
number as number_platform,
scene as scene_platform,
select as select_platform,
sensor as sensor_platform,
siren as siren_platform,
@ -96,10 +95,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
cv.ensure_list,
[number_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.SCENE.value: vol.All(
cv.ensure_list,
[scene_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.SCENE.value: vol.All(cv.ensure_list, [dict]),
Platform.SELECT.value: vol.All(
cv.ensure_list,
[select_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]

View file

@ -1,7 +1,6 @@
"""Support for MQTT scenes."""
from __future__ import annotations
import functools
from typing import Any
import voluptuous as vol
@ -13,11 +12,11 @@ from homeassistant.const import CONF_NAME, CONF_PAYLOAD_ON
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 MQTT_BASE_SCHEMA
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
DEFAULT_NAME = "MQTT Scene"
@ -43,21 +42,15 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MQTT scene 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,
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(