Do not fail MQTT setup if events or sensors configured via yaml can't be validated (#102309)
* Add event and sensor * Cleanup unused code * Schema cannot be None for supported platform
This commit is contained in:
parent
f85b4f734c
commit
7d9014ae41
8 changed files with 44 additions and 95 deletions
|
@ -3,7 +3,6 @@ from __future__ import annotations
|
|||
|
||||
from collections.abc import Callable
|
||||
from datetime import datetime, timedelta
|
||||
import functools
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
|
@ -33,7 +32,7 @@ from homeassistant.core import CALLBACK_TYPE, HomeAssistant, State, callback
|
|||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.event import async_call_later
|
||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
||||
from homeassistant.helpers.typing import ConfigType
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from . import subscription
|
||||
|
@ -44,7 +43,7 @@ from .mixins import (
|
|||
MQTT_ENTITY_COMMON_SCHEMA,
|
||||
MqttAvailability,
|
||||
MqttEntity,
|
||||
async_setup_entry_helper,
|
||||
async_mqtt_entry_helper,
|
||||
write_state_on_attr_change,
|
||||
)
|
||||
from .models import (
|
||||
|
@ -106,21 +105,15 @@ async def async_setup_entry(
|
|||
async_add_entities: AddEntitiesCallback,
|
||||
) -> None:
|
||||
"""Set up MQTT sensor 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,
|
||||
MqttSensor,
|
||||
sensor.DOMAIN,
|
||||
async_add_entities,
|
||||
DISCOVERY_SCHEMA,
|
||||
PLATFORM_SCHEMA_MODERN,
|
||||
)
|
||||
await async_setup_entry_helper(hass, sensor.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 MQTT sensor."""
|
||||
async_add_entities([MqttSensor(hass, config, config_entry, discovery_data)])
|
||||
|
||||
|
||||
class MqttSensor(MqttEntity, RestoreSensor):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue