Do not fail MQTT setup if camera's configured via yaml can't be validated (#102302)

Add camera
This commit is contained in:
Jan Bouwhuis 2023-10-19 18:17:06 +02:00 committed by GitHub
parent 651b725cc0
commit fb984b5218
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 21 deletions

View file

@ -2,7 +2,6 @@
from __future__ import annotations
from base64 import b64decode
import functools
import logging
from typing import TYPE_CHECKING
@ -21,7 +20,7 @@ from . import subscription
from .config import MQTT_BASE_SCHEMA
from .const import CONF_QOS, CONF_TOPIC
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 .util import valid_subscribe_topic
@ -61,21 +60,15 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MQTT camera 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,
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):

View file

@ -16,7 +16,6 @@ from homeassistant.helpers import config_validation as cv
from . import (
button as button_platform,
camera as camera_platform,
climate as climate_platform,
cover as cover_platform,
device_tracker as device_tracker_platform,
@ -59,10 +58,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
cv.ensure_list,
[button_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.CAMERA.value: vol.All(
cv.ensure_list,
[camera_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.CAMERA.value: vol.All(cv.ensure_list, [dict]),
Platform.CLIMATE.value: vol.All(
cv.ensure_list,
[climate_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]