Browse media class (#39698)
This commit is contained in:
parent
13a6aaa6ff
commit
df8daf561e
14 changed files with 342 additions and 235 deletions
|
@ -1,17 +1,30 @@
|
|||
"""Test Media Source model methods."""
|
||||
from homeassistant.components.media_player.const import MEDIA_TYPE_MUSIC
|
||||
from homeassistant.components.media_source import const, models
|
||||
|
||||
|
||||
async def test_browse_media_to_media_player_item():
|
||||
"""Test BrowseMedia conversion to media player item dict."""
|
||||
base = models.BrowseMedia(const.DOMAIN, "media", "media/", False, True)
|
||||
async def test_browse_media_as_dict():
|
||||
"""Test BrowseMediaSource conversion to media player item dict."""
|
||||
base = models.BrowseMediaSource(
|
||||
domain=const.DOMAIN,
|
||||
identifier="media",
|
||||
media_content_type="folder",
|
||||
title="media/",
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
)
|
||||
base.children = [
|
||||
models.BrowseMedia(
|
||||
const.DOMAIN, "media/test.mp3", "test.mp3", True, False, "audio/mp3"
|
||||
models.BrowseMediaSource(
|
||||
domain=const.DOMAIN,
|
||||
identifier="media/test.mp3",
|
||||
media_content_type=MEDIA_TYPE_MUSIC,
|
||||
title="test.mp3",
|
||||
can_play=True,
|
||||
can_expand=False,
|
||||
)
|
||||
]
|
||||
|
||||
item = base.to_media_player_item()
|
||||
item = base.as_dict()
|
||||
assert item["title"] == "media/"
|
||||
assert item["media_content_type"] == "folder"
|
||||
assert item["media_content_id"] == f"{const.URI_SCHEME}{const.DOMAIN}/media"
|
||||
|
@ -21,6 +34,26 @@ async def test_browse_media_to_media_player_item():
|
|||
assert item["children"][0]["title"] == "test.mp3"
|
||||
|
||||
|
||||
async def test_browse_media_parent_no_children():
|
||||
"""Test BrowseMediaSource conversion to media player item dict."""
|
||||
base = models.BrowseMediaSource(
|
||||
domain=const.DOMAIN,
|
||||
identifier="media",
|
||||
media_content_type="folder",
|
||||
title="media/",
|
||||
can_play=False,
|
||||
can_expand=True,
|
||||
)
|
||||
|
||||
item = base.as_dict()
|
||||
assert item["title"] == "media/"
|
||||
assert item["media_content_type"] == "folder"
|
||||
assert item["media_content_id"] == f"{const.URI_SCHEME}{const.DOMAIN}/media"
|
||||
assert not item["can_play"]
|
||||
assert item["can_expand"]
|
||||
assert len(item["children"]) == 0
|
||||
|
||||
|
||||
async def test_media_source_default_name():
|
||||
"""Test MediaSource uses domain as default name."""
|
||||
source = models.MediaSource(const.DOMAIN)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue