mirror of
https://github.com/home-assistant/core.git
synced 2025-04-24 01:08:12 +00:00
Shorten album titles when browsing artist (#57027)
This commit is contained in:
parent
19d54399c2
commit
33541ab287
@ -5,7 +5,10 @@ def pretty_title(media, short_name=False):
|
||||
"""Return a formatted title for the given media item."""
|
||||
year = None
|
||||
if media.type == "album":
|
||||
title = f"{media.parentTitle} - {media.title}"
|
||||
if short_name:
|
||||
title = media.title
|
||||
else:
|
||||
title = f"{media.parentTitle} - {media.title}"
|
||||
elif media.type == "episode":
|
||||
title = f"{media.seasonEpisode.upper()} - {media.title}"
|
||||
if not short_name:
|
||||
|
@ -46,6 +46,18 @@ class MockPlexEpisode:
|
||||
type = "episode"
|
||||
|
||||
|
||||
class MockPlexArtist:
|
||||
"""Mock a plexapi Artist instance."""
|
||||
|
||||
ratingKey = 300
|
||||
title = "Artist"
|
||||
type = "artist"
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over albums."""
|
||||
yield MockPlexAlbum()
|
||||
|
||||
|
||||
class MockPlexAlbum:
|
||||
"""Mock a plexapi Album instance."""
|
||||
|
||||
@ -53,7 +65,7 @@ class MockPlexAlbum:
|
||||
parentTitle = "Artist"
|
||||
title = "Album"
|
||||
type = "album"
|
||||
year = 2001
|
||||
year = 2019
|
||||
|
||||
def __iter__(self):
|
||||
"""Iterate over tracks."""
|
||||
@ -290,11 +302,13 @@ async def test_browse_media(
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "library"
|
||||
assert result["title"] == "Music"
|
||||
|
||||
# Browse into a Plex album
|
||||
# Browse into a Plex artist
|
||||
msg_id += 1
|
||||
mock_album = MockPlexAlbum()
|
||||
mock_artist = MockPlexArtist()
|
||||
mock_album = next(iter(MockPlexArtist()))
|
||||
mock_track = next(iter(MockPlexAlbum()))
|
||||
with patch.object(
|
||||
mock_plex_server, "fetch_item", return_value=mock_album
|
||||
mock_plex_server, "fetch_item", return_value=mock_artist
|
||||
) as mock_fetch:
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
@ -312,14 +326,35 @@ async def test_browse_media(
|
||||
msg = await websocket_client.receive_json()
|
||||
|
||||
assert mock_fetch.called
|
||||
assert msg["success"]
|
||||
result = msg["result"]
|
||||
result_id = int(result[ATTR_MEDIA_CONTENT_ID])
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "artist"
|
||||
assert result["title"] == mock_artist.title
|
||||
assert result["children"][0]["title"] == f"{mock_album.title} ({mock_album.year})"
|
||||
|
||||
# Browse into a Plex album
|
||||
msg_id += 1
|
||||
await websocket_client.send_json(
|
||||
{
|
||||
"id": msg_id,
|
||||
"type": "media_player/browse_media",
|
||||
"entity_id": media_players[0],
|
||||
ATTR_MEDIA_CONTENT_TYPE: result["children"][-1][ATTR_MEDIA_CONTENT_TYPE],
|
||||
ATTR_MEDIA_CONTENT_ID: str(result["children"][-1][ATTR_MEDIA_CONTENT_ID]),
|
||||
}
|
||||
)
|
||||
msg = await websocket_client.receive_json()
|
||||
|
||||
assert msg["success"]
|
||||
result = msg["result"]
|
||||
result_id = int(result[ATTR_MEDIA_CONTENT_ID])
|
||||
assert result[ATTR_MEDIA_CONTENT_TYPE] == "album"
|
||||
assert (
|
||||
result["title"]
|
||||
== f"{mock_album.parentTitle} - {mock_album.title} ({mock_album.year})"
|
||||
== f"{mock_artist.title} - {mock_album.title} ({mock_album.year})"
|
||||
)
|
||||
assert result["children"][0]["title"] == f"{mock_track.index}. {mock_track.title}"
|
||||
|
||||
# Browse into a non-existent TV season
|
||||
unknown_key = 99999999999999
|
||||
|
Loading…
x
Reference in New Issue
Block a user