mirror of
https://github.com/home-assistant/core.git
synced 2026-09-18 06:28:02 +01:00
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
71 lines
1.8 KiB
Python
71 lines
1.8 KiB
Python
"""Helper utilities for collection image tests."""
|
|
|
|
from typing import Any
|
|
|
|
from homeassistant.components.collection_image.const import CONF_MEDIA, DOMAIN
|
|
from homeassistant.components.media_player import BrowseMedia, MediaClass
|
|
from homeassistant.components.media_source import BrowseMediaSource
|
|
|
|
from tests.common import MockConfigEntry
|
|
|
|
|
|
def data_from_uri(uri: str | list[str]) -> dict[str, Any]:
|
|
"""Construct a data entry from one URI or a list of URIs."""
|
|
|
|
def media_item(content_id: str) -> dict[str, Any]:
|
|
return {
|
|
"media_content_id": content_id,
|
|
"media_content_type": "",
|
|
"metadata": {"a": "b"},
|
|
}
|
|
|
|
media: dict[str, Any] | list[dict[str, Any]]
|
|
if isinstance(uri, str):
|
|
media = media_item(uri)
|
|
else:
|
|
media = [media_item(item) for item in uri]
|
|
|
|
return {CONF_MEDIA: media}
|
|
|
|
|
|
def config_entry_from_uri(uri: str | list[str]) -> MockConfigEntry:
|
|
"""Construct a mock config entry from one URI or a list of URIs."""
|
|
return MockConfigEntry(
|
|
data=data_from_uri(uri),
|
|
domain=DOMAIN,
|
|
title="Random Image",
|
|
)
|
|
|
|
|
|
def image(
|
|
media_content_id: str,
|
|
*,
|
|
title: str = "a picture",
|
|
) -> BrowseMedia:
|
|
"""Create a playable image browse result."""
|
|
return BrowseMedia(
|
|
media_class=MediaClass.IMAGE,
|
|
media_content_id=media_content_id,
|
|
media_content_type="image/png",
|
|
title=title,
|
|
can_play=True,
|
|
can_expand=False,
|
|
)
|
|
|
|
|
|
def directory(
|
|
title: str,
|
|
*children: BrowseMedia,
|
|
) -> BrowseMediaSource:
|
|
"""Create an expandable browse result."""
|
|
return BrowseMediaSource(
|
|
domain=None,
|
|
identifier=None,
|
|
media_class="",
|
|
media_content_type="",
|
|
title=title,
|
|
can_play=False,
|
|
can_expand=True,
|
|
children=list(children),
|
|
)
|