Do not fail MQTT setup if camera's configured via yaml can't be validated (#102302)
Add camera
This commit is contained in:
parent
651b725cc0
commit
fb984b5218
2 changed files with 10 additions and 21 deletions
|
@ -2,7 +2,6 @@
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
@ -21,7 +20,7 @@ from . import subscription
|
||||||
from .config import MQTT_BASE_SCHEMA
|
from .config import MQTT_BASE_SCHEMA
|
||||||
from .const import CONF_QOS, CONF_TOPIC
|
from .const import CONF_QOS, CONF_TOPIC
|
||||||
from .debug_info import log_messages
|
from .debug_info import log_messages
|
||||||
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 .models import ReceiveMessage
|
from .models import ReceiveMessage
|
||||||
from .util import valid_subscribe_topic
|
from .util import valid_subscribe_topic
|
||||||
|
|
||||||
|
@ -61,21 +60,15 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT camera through YAML and through MQTT discovery."""
|
"""Set up MQTT camera 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,
|
||||||
|
MqttCamera,
|
||||||
|
camera.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, camera.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 Camera."""
|
|
||||||
async_add_entities([MqttCamera(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttCamera(MqttEntity, Camera):
|
class MqttCamera(MqttEntity, Camera):
|
||||||
|
|
|
@ -16,7 +16,6 @@ from homeassistant.helpers import config_validation as cv
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
button as button_platform,
|
button as button_platform,
|
||||||
camera as camera_platform,
|
|
||||||
climate as climate_platform,
|
climate as climate_platform,
|
||||||
cover as cover_platform,
|
cover as cover_platform,
|
||||||
device_tracker as device_tracker_platform,
|
device_tracker as device_tracker_platform,
|
||||||
|
@ -59,10 +58,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[button_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[button_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.CAMERA.value: vol.All(
|
Platform.CAMERA.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[camera_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.CLIMATE.value: vol.All(
|
Platform.CLIMATE.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[climate_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[climate_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue