mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 14:27:07 +00:00
Fix browsing Audible Favorites in Sonos (#140378)
* initial commit * updates * update test data
This commit is contained in:
parent
7bdec5f19f
commit
6c54f8dff2
@ -32,6 +32,7 @@ SONOS_TRACKS = "tracks"
|
|||||||
SONOS_COMPOSER = "composers"
|
SONOS_COMPOSER = "composers"
|
||||||
SONOS_RADIO = "radio"
|
SONOS_RADIO = "radio"
|
||||||
SONOS_OTHER_ITEM = "other items"
|
SONOS_OTHER_ITEM = "other items"
|
||||||
|
SONOS_AUDIO_BOOK = "audio book"
|
||||||
|
|
||||||
SONOS_STATE_PLAYING = "PLAYING"
|
SONOS_STATE_PLAYING = "PLAYING"
|
||||||
SONOS_STATE_TRANSITIONING = "TRANSITIONING"
|
SONOS_STATE_TRANSITIONING = "TRANSITIONING"
|
||||||
@ -67,6 +68,7 @@ SONOS_TO_MEDIA_CLASSES = {
|
|||||||
"object.item": MediaClass.TRACK,
|
"object.item": MediaClass.TRACK,
|
||||||
"object.item.audioItem.musicTrack": MediaClass.TRACK,
|
"object.item.audioItem.musicTrack": MediaClass.TRACK,
|
||||||
"object.item.audioItem.audioBroadcast": MediaClass.GENRE,
|
"object.item.audioItem.audioBroadcast": MediaClass.GENRE,
|
||||||
|
"object.item.audioItem.audioBook": MediaClass.TRACK,
|
||||||
}
|
}
|
||||||
|
|
||||||
SONOS_TO_MEDIA_TYPES = {
|
SONOS_TO_MEDIA_TYPES = {
|
||||||
@ -84,6 +86,7 @@ SONOS_TO_MEDIA_TYPES = {
|
|||||||
"object.container.playlistContainer.sameArtist": MediaType.ARTIST,
|
"object.container.playlistContainer.sameArtist": MediaType.ARTIST,
|
||||||
"object.container.playlistContainer": MediaType.PLAYLIST,
|
"object.container.playlistContainer": MediaType.PLAYLIST,
|
||||||
"object.item.audioItem.musicTrack": MediaType.TRACK,
|
"object.item.audioItem.musicTrack": MediaType.TRACK,
|
||||||
|
"object.item.audioItem.audioBook": MediaType.TRACK,
|
||||||
}
|
}
|
||||||
|
|
||||||
MEDIA_TYPES_TO_SONOS: dict[MediaType | str, str] = {
|
MEDIA_TYPES_TO_SONOS: dict[MediaType | str, str] = {
|
||||||
@ -113,6 +116,7 @@ SONOS_TYPES_MAPPING = {
|
|||||||
"object.item": SONOS_OTHER_ITEM,
|
"object.item": SONOS_OTHER_ITEM,
|
||||||
"object.item.audioItem.musicTrack": SONOS_TRACKS,
|
"object.item.audioItem.musicTrack": SONOS_TRACKS,
|
||||||
"object.item.audioItem.audioBroadcast": SONOS_RADIO,
|
"object.item.audioItem.audioBroadcast": SONOS_RADIO,
|
||||||
|
"object.item.audioItem.audioBook": SONOS_AUDIO_BOOK,
|
||||||
}
|
}
|
||||||
|
|
||||||
LIBRARY_TITLES_MAPPING = {
|
LIBRARY_TITLES_MAPPING = {
|
||||||
|
@ -34,5 +34,23 @@
|
|||||||
"protocol_info": "a:b:c:d"
|
"protocol_info": "a:b:c:d"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"title": "American Tall Tales",
|
||||||
|
"parent_id": "FV:2",
|
||||||
|
"item_id": "FV:2/66",
|
||||||
|
"restricted": false,
|
||||||
|
"resource_meta_data": "<DIDL-Lite xmlns:dc=\"http://purl.org/dc/elements/1.1/\" xmlns:upnp=\"urn:schemas-upnp-org:metadata-1-0/upnp/\" xmlns:r=\"urn:schemas-rinconnetworks-com:metadata-1-0/\" xmlns=\"urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/\"><item id=\"101340c8reftitleC9F27_com\" parentID=\"101340c8reftitleC9F27_com\" restricted=\"true\"><dc:title>American Tall Tales</dc:title><upnp:class>object.item.audioItem.audioBook</upnp:class><desc id=\"cdudn\" nameSpace=\"urn:schemas-rinconnetworks-com:metadata-1-0/\">SA_RINCON61191_X_#Svc6-0-Token</desc></item></DIDL-Lite>",
|
||||||
|
"resources": [
|
||||||
|
{
|
||||||
|
"uri": "x-rincon-cpcontainer:101340c8reftitle%C9F27_com?sid=239&flags=16584&sn=5",
|
||||||
|
"protocol_info": "x-rincon-cpcontainer:*:*:*"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"desc": null,
|
||||||
|
"album_art_uri": "https://m.media-amazon.com/images/I/810lqLo5m0L._SL600_.jpg",
|
||||||
|
"type": "instantPlay",
|
||||||
|
"description": "Audible",
|
||||||
|
"favorite_nr": "0"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -1,4 +1,74 @@
|
|||||||
# serializer version: 1
|
# serializer version: 1
|
||||||
|
# name: test_browse_media_favorites[-favorites]
|
||||||
|
dict({
|
||||||
|
'can_expand': True,
|
||||||
|
'can_play': False,
|
||||||
|
'children': list([
|
||||||
|
dict({
|
||||||
|
'can_expand': True,
|
||||||
|
'can_play': False,
|
||||||
|
'children_media_class': None,
|
||||||
|
'media_class': 'album',
|
||||||
|
'media_content_id': 'object.container.album.musicAlbum',
|
||||||
|
'media_content_type': 'favorites_folder',
|
||||||
|
'thumbnail': None,
|
||||||
|
'title': 'Albums',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'can_expand': True,
|
||||||
|
'can_play': False,
|
||||||
|
'children_media_class': None,
|
||||||
|
'media_class': 'track',
|
||||||
|
'media_content_id': 'object.item.audioItem.audioBook',
|
||||||
|
'media_content_type': 'favorites_folder',
|
||||||
|
'thumbnail': None,
|
||||||
|
'title': 'Audio Book',
|
||||||
|
}),
|
||||||
|
dict({
|
||||||
|
'can_expand': True,
|
||||||
|
'can_play': False,
|
||||||
|
'children_media_class': None,
|
||||||
|
'media_class': 'genre',
|
||||||
|
'media_content_id': 'object.item.audioItem.audioBroadcast',
|
||||||
|
'media_content_type': 'favorites_folder',
|
||||||
|
'thumbnail': None,
|
||||||
|
'title': 'Radio',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'children_media_class': 'directory',
|
||||||
|
'media_class': 'directory',
|
||||||
|
'media_content_id': '',
|
||||||
|
'media_content_type': 'favorites',
|
||||||
|
'not_shown': 0,
|
||||||
|
'thumbnail': None,
|
||||||
|
'title': 'Favorites',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
|
# name: test_browse_media_favorites[object.item.audioItem.audioBook-favorites_folder]
|
||||||
|
dict({
|
||||||
|
'can_expand': True,
|
||||||
|
'can_play': False,
|
||||||
|
'children': list([
|
||||||
|
dict({
|
||||||
|
'can_expand': False,
|
||||||
|
'can_play': True,
|
||||||
|
'children_media_class': None,
|
||||||
|
'media_class': 'track',
|
||||||
|
'media_content_id': 'FV:2/66',
|
||||||
|
'media_content_type': 'favorite_item_id',
|
||||||
|
'thumbnail': 'https://m.media-amazon.com/images/I/810lqLo5m0L._SL600_.jpg',
|
||||||
|
'title': 'American Tall Tales',
|
||||||
|
}),
|
||||||
|
]),
|
||||||
|
'children_media_class': 'track',
|
||||||
|
'media_class': 'directory',
|
||||||
|
'media_content_id': '',
|
||||||
|
'media_content_type': 'favorites',
|
||||||
|
'not_shown': 0,
|
||||||
|
'thumbnail': None,
|
||||||
|
'title': 'Audio Book',
|
||||||
|
})
|
||||||
|
# ---
|
||||||
# name: test_browse_media_library
|
# name: test_browse_media_library
|
||||||
list([
|
list([
|
||||||
dict({
|
dict({
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
|
import pytest
|
||||||
from syrupy import SnapshotAssertion
|
from syrupy import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.media_player import BrowseMedia, MediaClass, MediaType
|
from homeassistant.components.media_player import BrowseMedia, MediaClass, MediaType
|
||||||
@ -176,3 +177,39 @@ async def test_browse_media_library_albums(
|
|||||||
assert response["success"]
|
assert response["success"]
|
||||||
assert response["result"]["children"] == snapshot
|
assert response["result"]["children"] == snapshot
|
||||||
assert soco_mock.music_library.browse_by_idstring.call_count == 1
|
assert soco_mock.music_library.browse_by_idstring.call_count == 1
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("media_content_id", "media_content_type"),
|
||||||
|
[
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
"favorites",
|
||||||
|
),
|
||||||
|
(
|
||||||
|
"object.item.audioItem.audioBook",
|
||||||
|
"favorites_folder",
|
||||||
|
),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
async def test_browse_media_favorites(
|
||||||
|
async_autosetup_sonos,
|
||||||
|
hass_ws_client: WebSocketGenerator,
|
||||||
|
snapshot: SnapshotAssertion,
|
||||||
|
media_content_id,
|
||||||
|
media_content_type,
|
||||||
|
) -> None:
|
||||||
|
"""Test the async_browse_media method."""
|
||||||
|
client = await hass_ws_client()
|
||||||
|
await client.send_json(
|
||||||
|
{
|
||||||
|
"id": 1,
|
||||||
|
"type": "media_player/browse_media",
|
||||||
|
"entity_id": "media_player.zone_a",
|
||||||
|
"media_content_id": media_content_id,
|
||||||
|
"media_content_type": media_content_type,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
response = await client.receive_json()
|
||||||
|
assert response["success"]
|
||||||
|
assert response["result"] == snapshot
|
||||||
|
Loading…
x
Reference in New Issue
Block a user