mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 00:07:10 +00:00
Show Sonos playlists under favorites (#142357)
* Update media_browser.py * Update favorites.py * Update media_player.py * Update media_browser.py * Update media_player.py * Update favorites.py * Update media_browser.py * Update media_player.py * Update favorites.py * Added/fixed testing for showing sonos native playlists in the media browser * Create a DidlFavorite to wrap playlists. * Processed PR feedback
This commit is contained in:
parent
91f01d660f
commit
a21e586140
@ -106,6 +106,9 @@ class SonosFavorites(SonosHouseholdCoordinator):
|
||||
def update_cache(self, soco: SoCo, update_id: int | None = None) -> bool:
|
||||
"""Update cache of known favorites and return if cache has changed."""
|
||||
new_favorites = soco.music_library.get_sonos_favorites(full_album_art_uri=True)
|
||||
new_playlists = soco.music_library.get_music_library_information(
|
||||
"sonos_playlists", full_album_art_uri=True
|
||||
)
|
||||
|
||||
# Polled update_id values do not match event_id values
|
||||
# Each speaker can return a different polled update_id
|
||||
@ -131,6 +134,16 @@ class SonosFavorites(SonosHouseholdCoordinator):
|
||||
except SoCoException as ex:
|
||||
# Skip unknown types
|
||||
_LOGGER.error("Unhandled favorite '%s': %s", fav.title, ex)
|
||||
for playlist in new_playlists:
|
||||
playlist_reference = DidlFavorite(
|
||||
title=playlist.title,
|
||||
parent_id=playlist.parent_id,
|
||||
item_id=playlist.item_id,
|
||||
resources=playlist.resources,
|
||||
desc=playlist.desc,
|
||||
)
|
||||
playlist_reference.reference = playlist
|
||||
self._favorites.append(playlist_reference)
|
||||
|
||||
_LOGGER.debug(
|
||||
"Cached %s favorites for household %s using %s",
|
||||
|
@ -505,7 +505,7 @@ def mock_browse_by_idstring(
|
||||
|
||||
|
||||
def mock_get_music_library_information(
|
||||
search_type: str, search_term: str, full_album_art_uri: bool = True
|
||||
search_type: str, search_term: str | None = None, full_album_art_uri: bool = True
|
||||
) -> list[MockMusicServiceItem]:
|
||||
"""Mock the call to get music library information."""
|
||||
if search_type == "albums" and search_term == "Abbey Road":
|
||||
@ -517,6 +517,10 @@ def mock_get_music_library_information(
|
||||
"object.container.album.musicAlbum",
|
||||
)
|
||||
]
|
||||
if search_type == "sonos_playlists":
|
||||
playlists = load_json_value_fixture("sonos_playlists.json", "sonos")
|
||||
playlists_list = [DidlPlaylistContainer.from_dict(pl) for pl in playlists]
|
||||
return SearchResult(playlists_list, "sonos_playlists", 1, 1, 0)
|
||||
return []
|
||||
|
||||
|
||||
|
@ -16,6 +16,17 @@
|
||||
'thumbnail': None,
|
||||
'title': 'Albums',
|
||||
}),
|
||||
dict({
|
||||
'can_expand': True,
|
||||
'can_play': False,
|
||||
'can_search': False,
|
||||
'children_media_class': None,
|
||||
'media_class': 'playlist',
|
||||
'media_content_id': 'object.container.playlistContainer',
|
||||
'media_content_type': 'favorites_folder',
|
||||
'thumbnail': None,
|
||||
'title': 'Playlists',
|
||||
}),
|
||||
dict({
|
||||
'can_expand': True,
|
||||
'can_play': False,
|
||||
|
Loading…
x
Reference in New Issue
Block a user