Normalize enqueuing Plex media on Sonos (#68132)
This commit is contained in:
parent
a8dae97917
commit
f75d621888
2 changed files with 13 additions and 10 deletions
|
@ -574,11 +574,14 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
|
|||
else:
|
||||
shuffle = False
|
||||
media = lookup_plex_media(self.hass, media_type, json.dumps(payload))
|
||||
if not kwargs.get(ATTR_MEDIA_ENQUEUE):
|
||||
soco.clear_queue()
|
||||
if shuffle:
|
||||
self.set_shuffle(True)
|
||||
plex_plugin.play_now(media)
|
||||
if kwargs.get(ATTR_MEDIA_ENQUEUE):
|
||||
plex_plugin.add_to_queue(media)
|
||||
else:
|
||||
soco.clear_queue()
|
||||
plex_plugin.add_to_queue(media)
|
||||
soco.play_from_queue(0)
|
||||
return
|
||||
|
||||
share_link = self.coordinator.share_link
|
||||
|
|
|
@ -25,8 +25,8 @@ async def test_plex_play_media(hass, async_autosetup_sonos):
|
|||
with patch(
|
||||
"homeassistant.components.sonos.media_player.lookup_plex_media"
|
||||
) as mock_lookup, patch(
|
||||
"soco.plugins.plex.PlexPlugin.play_now"
|
||||
) as mock_play_now, patch(
|
||||
"soco.plugins.plex.PlexPlugin.add_to_queue"
|
||||
) as mock_add_to_queue, patch(
|
||||
"homeassistant.components.sonos.media_player.SonosMediaPlayerEntity.set_shuffle"
|
||||
) as mock_shuffle:
|
||||
# Test successful Plex service call
|
||||
|
@ -42,14 +42,14 @@ async def test_plex_play_media(hass, async_autosetup_sonos):
|
|||
)
|
||||
|
||||
assert len(mock_lookup.mock_calls) == 1
|
||||
assert len(mock_play_now.mock_calls) == 1
|
||||
assert len(mock_add_to_queue.mock_calls) == 1
|
||||
assert not mock_shuffle.called
|
||||
assert mock_lookup.mock_calls[0][1][1] == MEDIA_TYPE_MUSIC
|
||||
assert mock_lookup.mock_calls[0][1][2] == media_content_id
|
||||
|
||||
# Test handling shuffle in payload
|
||||
mock_lookup.reset_mock()
|
||||
mock_play_now.reset_mock()
|
||||
mock_add_to_queue.reset_mock()
|
||||
shuffle_media_content_id = '{"library_name": "Music", "artist_name": "Artist", "album_name": "Album", "shuffle": 1}'
|
||||
|
||||
assert await hass.services.async_call(
|
||||
|
@ -65,14 +65,14 @@ async def test_plex_play_media(hass, async_autosetup_sonos):
|
|||
|
||||
assert mock_shuffle.called
|
||||
assert len(mock_lookup.mock_calls) == 1
|
||||
assert len(mock_play_now.mock_calls) == 1
|
||||
assert len(mock_add_to_queue.mock_calls) == 1
|
||||
assert mock_lookup.mock_calls[0][1][1] == MEDIA_TYPE_MUSIC
|
||||
assert mock_lookup.mock_calls[0][1][2] == media_content_id
|
||||
|
||||
# Test failed Plex service call
|
||||
mock_lookup.reset_mock()
|
||||
mock_lookup.side_effect = HomeAssistantError
|
||||
mock_play_now.reset_mock()
|
||||
mock_add_to_queue.reset_mock()
|
||||
|
||||
with pytest.raises(HomeAssistantError):
|
||||
await hass.services.async_call(
|
||||
|
@ -86,4 +86,4 @@ async def test_plex_play_media(hass, async_autosetup_sonos):
|
|||
blocking=True,
|
||||
)
|
||||
assert mock_lookup.called
|
||||
assert not mock_play_now.called
|
||||
assert not mock_add_to_queue.called
|
||||
|
|
Loading…
Add table
Reference in a new issue