Do not fail MQTT setup if update entities configured via yaml can't be validated (#102324)
This commit is contained in:
parent
3014a651c3
commit
f1eb28b7ac
2 changed files with 12 additions and 23 deletions
|
@ -19,7 +19,6 @@ from . import (
|
||||||
event as event_platform,
|
event as event_platform,
|
||||||
number as number_platform,
|
number as number_platform,
|
||||||
sensor as sensor_platform,
|
sensor as sensor_platform,
|
||||||
update as update_platform,
|
|
||||||
)
|
)
|
||||||
from .const import (
|
from .const import (
|
||||||
CONF_BIRTH_MESSAGE,
|
CONF_BIRTH_MESSAGE,
|
||||||
|
@ -70,10 +69,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
Platform.SIREN.value: vol.All(cv.ensure_list, [dict]),
|
Platform.SIREN.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.SWITCH.value: vol.All(cv.ensure_list, [dict]),
|
Platform.SWITCH.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.TEXT.value: vol.All(cv.ensure_list, [dict]),
|
Platform.TEXT.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.UPDATE.value: vol.All(
|
Platform.UPDATE.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[update_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.VACUUM.value: vol.All(cv.ensure_list, [dict]),
|
Platform.VACUUM.value: vol.All(cv.ensure_list, [dict]),
|
||||||
Platform.WATER_HEATER.value: vol.All(cv.ensure_list, [dict]),
|
Platform.WATER_HEATER.value: vol.All(cv.ensure_list, [dict]),
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
"""Configure update platform in a device through MQTT topic."""
|
"""Configure update platform in a device through MQTT topic."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
from typing import Any, TypedDict, cast
|
from typing import Any, TypedDict, cast
|
||||||
|
|
||||||
|
@ -19,7 +18,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 homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
from homeassistant.util.json import JSON_DECODE_EXCEPTIONS, json_loads
|
||||||
|
|
||||||
from . import subscription
|
from . import subscription
|
||||||
|
@ -36,7 +35,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 MessageCallbackType, MqttValueTemplate, ReceiveMessage
|
from .models import MessageCallbackType, MqttValueTemplate, ReceiveMessage
|
||||||
|
@ -91,22 +90,16 @@ async def async_setup_entry(
|
||||||
config_entry: ConfigEntry,
|
config_entry: ConfigEntry,
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT update through YAML and through MQTT discovery."""
|
"""Set up MQTT update entity 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,
|
||||||
|
MqttUpdate,
|
||||||
|
update.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, update.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 update."""
|
|
||||||
async_add_entities([MqttUpdate(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttUpdate(MqttEntity, UpdateEntity, RestoreEntity):
|
class MqttUpdate(MqttEntity, UpdateEntity, RestoreEntity):
|
||||||
|
|
Loading…
Add table
Reference in a new issue