mirror of
https://github.com/home-assistant/core.git
synced 2025-04-23 16:57:53 +00:00
Fix lookup by Plex media key when playing on Sonos (#38119)
This commit is contained in:
parent
364aaceb1c
commit
67312e2d42
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user