From f1eb28b7acd2c54b288e96c258c3ad73490f338c Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Fri, 20 Oct 2023 10:14:25 +0200 Subject: [PATCH] Do not fail MQTT setup if update entities configured via yaml can't be validated (#102324) --- .../components/mqtt/config_integration.py | 6 +--- homeassistant/components/mqtt/update.py | 29 +++++++------------ 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/mqtt/config_integration.py b/homeassistant/components/mqtt/config_integration.py index 4a8532682fb..def93075303 100644 --- a/homeassistant/components/mqtt/config_integration.py +++ b/homeassistant/components/mqtt/config_integration.py @@ -19,7 +19,6 @@ from . import ( event as event_platform, number as number_platform, sensor as sensor_platform, - update as update_platform, ) from .const import ( CONF_BIRTH_MESSAGE, @@ -70,10 +69,7 @@ CONFIG_SCHEMA_BASE = vol.Schema( Platform.SIREN.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.UPDATE.value: vol.All( - cv.ensure_list, - [update_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type] - ), + Platform.UPDATE.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]), } diff --git a/homeassistant/components/mqtt/update.py b/homeassistant/components/mqtt/update.py index 45cca7279f9..c9ad17c078c 100644 --- a/homeassistant/components/mqtt/update.py +++ b/homeassistant/components/mqtt/update.py @@ -1,7 +1,6 @@ """Configure update platform in a device through MQTT topic.""" from __future__ import annotations -import functools import logging 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.entity_platform import AddEntitiesCallback 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 . import subscription @@ -36,7 +35,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 MessageCallbackType, MqttValueTemplate, ReceiveMessage @@ -91,22 +90,16 @@ async def async_setup_entry( config_entry: ConfigEntry, async_add_entities: AddEntitiesCallback, ) -> None: - """Set up MQTT update through YAML and through MQTT discovery.""" - setup = functools.partial( - _async_setup_entity, hass, async_add_entities, config_entry=config_entry + """Set up MQTT update entity through YAML and through MQTT discovery.""" + await async_mqtt_entry_helper( + 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):