Do not fail MQTT setup if images configured via yaml can't be validated (#102313)
Add image
This commit is contained in:
parent
3853214496
commit
d0341c9754
3 changed files with 12 additions and 25 deletions
|
@ -20,7 +20,6 @@ from . import (
|
||||||
cover as cover_platform,
|
cover as cover_platform,
|
||||||
event as event_platform,
|
event as event_platform,
|
||||||
humidifier as humidifier_platform,
|
humidifier as humidifier_platform,
|
||||||
image as image_platform,
|
|
||||||
lawn_mower as lawn_mower_platform,
|
lawn_mower as lawn_mower_platform,
|
||||||
lock as lock_platform,
|
lock as lock_platform,
|
||||||
number as number_platform,
|
number as number_platform,
|
||||||
|
@ -74,10 +73,7 @@ CONFIG_SCHEMA_BASE = vol.Schema(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[humidifier_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[humidifier_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
),
|
),
|
||||||
Platform.IMAGE.value: vol.All(
|
Platform.IMAGE.value: vol.All(cv.ensure_list, [dict]),
|
||||||
cv.ensure_list,
|
|
||||||
[image_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
|
||||||
),
|
|
||||||
Platform.LAWN_MOWER.value: vol.All(
|
Platform.LAWN_MOWER.value: vol.All(
|
||||||
cv.ensure_list,
|
cv.ensure_list,
|
||||||
[lawn_mower_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
[lawn_mower_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
|
||||||
|
|
|
@ -4,7 +4,6 @@ from __future__ import annotations
|
||||||
from base64 import b64decode
|
from base64 import b64decode
|
||||||
import binascii
|
import binascii
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
import functools
|
|
||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING, Any
|
from typing import TYPE_CHECKING, Any
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ from . import subscription
|
||||||
from .config import MQTT_BASE_SCHEMA
|
from .config import MQTT_BASE_SCHEMA
|
||||||
from .const import CONF_ENCODING, CONF_QOS
|
from .const import CONF_ENCODING, CONF_QOS
|
||||||
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 MessageCallbackType, MqttValueTemplate, ReceiveMessage
|
from .models import MessageCallbackType, MqttValueTemplate, ReceiveMessage
|
||||||
from .util import get_mqtt_data, valid_subscribe_topic
|
from .util import get_mqtt_data, valid_subscribe_topic
|
||||||
|
|
||||||
|
@ -79,21 +78,15 @@ async def async_setup_entry(
|
||||||
async_add_entities: AddEntitiesCallback,
|
async_add_entities: AddEntitiesCallback,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Set up MQTT image through YAML and through MQTT discovery."""
|
"""Set up MQTT image 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,
|
||||||
|
MqttImage,
|
||||||
|
image.DOMAIN,
|
||||||
|
async_add_entities,
|
||||||
|
DISCOVERY_SCHEMA,
|
||||||
|
PLATFORM_SCHEMA_MODERN,
|
||||||
)
|
)
|
||||||
await async_setup_entry_helper(hass, image.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 Image."""
|
|
||||||
async_add_entities([MqttImage(hass, config, config_entry, discovery_data)])
|
|
||||||
|
|
||||||
|
|
||||||
class MqttImage(MqttEntity, ImageEntity):
|
class MqttImage(MqttEntity, ImageEntity):
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
"""The tests for mqtt image component."""
|
"""The tests for mqtt image component."""
|
||||||
from base64 import b64encode
|
from base64 import b64encode
|
||||||
from contextlib import suppress
|
|
||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
import json
|
import json
|
||||||
import ssl
|
import ssl
|
||||||
|
@ -504,7 +503,7 @@ async def test_image_from_url_fails(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Invalid config for [mqtt]: Expected one of [`image_topic`, `url_topic`], got none",
|
"Expected one of [`image_topic`, `url_topic`], got none",
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
@ -516,8 +515,7 @@ async def test_image_config_fails(
|
||||||
error_msg: str,
|
error_msg: str,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test setup with minimum configuration."""
|
"""Test setup with minimum configuration."""
|
||||||
with suppress(AssertionError):
|
assert await mqtt_mock_entry()
|
||||||
await mqtt_mock_entry()
|
|
||||||
assert error_msg in caplog.text
|
assert error_msg in caplog.text
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue