Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not fail MQTT setup if images configured via yaml can't be validated #102313

Merged
merged 1 commit into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 1 addition & 5 deletions homeassistant/components/mqtt/config_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
event as event_platform,
fan as fan_platform,
humidifier as humidifier_platform,
image as image_platform,
lawn_mower as lawn_mower_platform,
light as light_platform,
lock as lock_platform,
Expand Down Expand Up @@ -92,10 +91,7 @@
cv.ensure_list,
[humidifier_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.IMAGE.value: vol.All(
cv.ensure_list,
[image_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
),
Platform.IMAGE.value: vol.All(cv.ensure_list, [dict]),
Platform.LAWN_MOWER.value: vol.All(
cv.ensure_list,
[lawn_mower_platform.PLATFORM_SCHEMA_MODERN], # type: ignore[has-type]
Expand Down
25 changes: 9 additions & 16 deletions homeassistant/components/mqtt/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from base64 import b64decode
import binascii
from collections.abc import Callable
import functools
import logging
from typing import TYPE_CHECKING, Any

Expand All @@ -27,7 +26,7 @@
from .config import MQTT_BASE_SCHEMA
from .const import CONF_ENCODING, CONF_QOS
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 .util import get_mqtt_data, valid_subscribe_topic

Expand Down Expand Up @@ -79,21 +78,15 @@ async def async_setup_entry(
async_add_entities: AddEntitiesCallback,
) -> None:
"""Set up MQTT image 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,
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):
Expand Down
6 changes: 2 additions & 4 deletions tests/components/mqtt/test_image.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""The tests for mqtt image component."""
from base64 import b64encode
from contextlib import suppress
from http import HTTPStatus
import json
import ssl
Expand Down Expand Up @@ -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",
),
],
)
Expand All @@ -516,8 +515,7 @@ async def test_image_config_fails(
error_msg: str,
) -> None:
"""Test setup with minimum configuration."""
with suppress(AssertionError):
await mqtt_mock_entry()
assert await mqtt_mock_entry()
assert error_msg in caplog.text


Expand Down