mirror of
https://github.com/home-assistant/core.git
synced 2025-07-15 09:17:10 +00:00
Do not fail MQTT setup if device trackers configured via yaml can't be validated (#102308)
Add device_tracker
This commit is contained in:
parent
fb984b5218
commit
3a4341dbeb
@ -18,7 +18,6 @@ from . import (
|
|||||||
button as button_platform,
|
button as button_platform,
|
||||||
climate as climate_platform,
|
climate as climate_platform,
|
||||||
cover as cover_platform,
|
cover as cover_platform,
|
||||||
device_tracker as device_tracker_platform,
|
|
||||||
event as event_platform,
|
event as event_platform,
|
||||||
fan as fan_platform,
|
fan as fan_platform,
|
||||||
humidifier as humidifier_platform,
|
humidifier as humidifier_platform,
|
||||||
@ -67,10 +66,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
|||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[cover_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[cover_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.DEVICE_TRACKER.value: vol.All(
|
Platform.DEVICE_TRACKER.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[device_tracker_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.EVENT.value: vol.All(
|
Platform.EVENT.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[event_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[event_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import functools
|
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
@ -26,7 +25,7 @@ from homeassistant.const import (
|
|||||||
from homeassistant.core import HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
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 . import subscription
|
from . import subscription
|
||||||
from .config import MQTT_BASE_SCHEMA
|
from .config import MQTT_BASE_SCHEMA
|
||||||
@ -36,7 +35,7 @@ from .mixins import (
|
|||||||
CONF_JSON_ATTRS_TOPIC,
|
CONF_JSON_ATTRS_TOPIC,
|
||||||
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 MqttValueTemplate, ReceiveMessage, ReceivePayloadType
|
from .models import MqttValueTemplate, ReceiveMessage, ReceivePayloadType
|
||||||
@ -85,22 +84,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 device_tracker through YAML and through MQTT discovery."""
|
"""Set up MQTT event 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,
|
||||||
|
MqttDeviceTracker,
|
||||||
|
device_tracker.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, device_tracker.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 Device Tracker entity."""
|
|
||||||
async_add_entities([MqttDeviceTracker(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttDeviceTracker(MqttEntity, TrackerEntity):
|
class MqttDeviceTracker(MqttEntity, TrackerEntity):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user