Add Sonos tests and update error handling for unknown media (#124578)
* initial commit * simplify tests
This commit is contained in:
parent
4ecc6555bf
commit
b4e20409de
3 changed files with 59 additions and 5 deletions
|
@ -672,14 +672,23 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
soco.play_from_queue(0)
|
||||
elif media_type in PLAYABLE_MEDIA_TYPES:
|
||||
item = media_browser.get_media(self.media.library, media_id, media_type)
|
||||
|
||||
if not item:
|
||||
_LOGGER.error('Could not find "%s" in the library', media_id)
|
||||
return
|
||||
|
||||
raise ServiceValidationError(
|
||||
translation_domain=SONOS_DOMAIN,
|
||||
translation_key="invalid_media",
|
||||
translation_placeholders={
|
||||
"media_id": media_id,
|
||||
},
|
||||
)
|
||||
self._play_media_queue(soco, item, enqueue)
|
||||
else:
|
||||
_LOGGER.error('Sonos does not support a media type of "%s"', media_type)
|
||||
raise ServiceValidationError(
|
||||
translation_domain=SONOS_DOMAIN,
|
||||
translation_key="invalid_content_type",
|
||||
translation_placeholders={
|
||||
"media_type": media_type,
|
||||
},
|
||||
)
|
||||
|
||||
def _play_media_queue(
|
||||
self, soco: SoCo, item: MusicServiceItem, enqueue: MediaPlayerEnqueue
|
||||
|
|
|
@ -185,6 +185,12 @@
|
|||
"invalid_sonos_playlist": {
|
||||
"message": "Could not find Sonos playlist: {name}"
|
||||
},
|
||||
"invalid_media": {
|
||||
"message": "Could not find media in library: {media_id}"
|
||||
},
|
||||
"invalid_content_type": {
|
||||
"message": "Sonos does not support media content type: {media_type}"
|
||||
},
|
||||
"announce_media_error": {
|
||||
"message": "Announcing clip {media_id} failed {response}"
|
||||
}
|
||||
|
|
|
@ -232,6 +232,45 @@ async def test_play_media_library(
|
|||
)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("media_content_type", "media_content_id", "message"),
|
||||
[
|
||||
(
|
||||
"artist",
|
||||
"A:ALBUM/UnknowAlbum",
|
||||
"Could not find media in library: A:ALBUM/UnknowAlbum",
|
||||
),
|
||||
(
|
||||
"UnknownContent",
|
||||
"A:ALBUM/UnknowAlbum",
|
||||
"Sonos does not support media content type: UnknownContent",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_play_media_library_content_error(
|
||||
hass: HomeAssistant,
|
||||
async_autosetup_sonos,
|
||||
media_content_type,
|
||||
media_content_id,
|
||||
message,
|
||||
) -> None:
|
||||
"""Test playing local library errors on content and content type."""
|
||||
with pytest.raises(
|
||||
ServiceValidationError,
|
||||
match=message,
|
||||
):
|
||||
await hass.services.async_call(
|
||||
MP_DOMAIN,
|
||||
SERVICE_PLAY_MEDIA,
|
||||
{
|
||||
ATTR_ENTITY_ID: "media_player.zone_a",
|
||||
ATTR_MEDIA_CONTENT_TYPE: media_content_type,
|
||||
ATTR_MEDIA_CONTENT_ID: media_content_id,
|
||||
},
|
||||
blocking=True,
|
||||
)
|
||||
|
||||
|
||||
_track_url = "S://192.168.42.100/music/iTunes/The%20Beatles/A%20Hard%20Day%2fs%I%20Should%20Have%20Known%20Better.mp3"
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue