Fix lookup by Plex media key when playing on Sonos (#38119)

This commit is contained in:
jjlawren 2020-08-03 05:40:48 -05:00 committed by GitHub
parent 364aaceb1c
commit 67312e2d42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 3 deletions

View File

@ -222,6 +222,9 @@ def play_on_sonos(hass, service_call):
if isinstance(content, int):
content = {"plex_key": content}
content_type = PLEX_DOMAIN
else:
content_type = "music"
plex_server_name = content.get("plex_server")
shuffle = content.pop("shuffle", 0)
@ -246,7 +249,7 @@ def play_on_sonos(hass, service_call):
)
return
media = plex_server.lookup_media("music", **content)
media = plex_server.lookup_media(content_type, **content)
if media is None:
_LOGGER.error("Media could not be found: %s", content)
return

View File

@ -1,4 +1,6 @@
"""Tests for Plex player playback methods/services."""
from plexapi.exceptions import NotFound
from homeassistant.components.media_player.const import (
ATTR_MEDIA_CONTENT_ID,
ATTR_MEDIA_CONTENT_TYPE,
@ -52,7 +54,7 @@ async def test_sonos_playback(hass):
True,
)
# Test success with dict
# Test success with plex_key
with patch.object(
hass.components.sonos,
"get_coordinator_name",
@ -69,7 +71,7 @@ async def test_sonos_playback(hass):
True,
)
# Test success with plex_key
# Test success with dict
with patch.object(
hass.components.sonos,
"get_coordinator_name",
@ -86,6 +88,23 @@ async def test_sonos_playback(hass):
True,
)
# Test media lookup failure
with patch.object(
hass.components.sonos,
"get_coordinator_name",
return_value="media_player.sonos_kitchen",
), patch.object(mock_plex_server, "fetchItem", side_effect=NotFound):
assert await hass.services.async_call(
DOMAIN,
SERVICE_PLAY_ON_SONOS,
{
ATTR_ENTITY_ID: "media_player.sonos_kitchen",
ATTR_MEDIA_CONTENT_TYPE: MEDIA_TYPE_MUSIC,
ATTR_MEDIA_CONTENT_ID: "999",
},
True,
)
# Test invalid Plex server requested
with patch.object(
hass.components.sonos,