mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 21:57:51 +00:00
Sonos playlists play media (#26054)
* Add handling for Sonos playlists in media_player.play_media * Avoid breaking change by falling back to previous behavior * Use the proper MEDIA_TYPE_PLAYLIST constant. * Addressed comments, restricting media_type to music or playlist
This commit is contained in:
parent
cf2d927f14
commit
7fd53ac912
@ -15,6 +15,7 @@ from homeassistant.components.media_player import MediaPlayerDevice
|
|||||||
from homeassistant.components.media_player.const import (
|
from homeassistant.components.media_player.const import (
|
||||||
ATTR_MEDIA_ENQUEUE,
|
ATTR_MEDIA_ENQUEUE,
|
||||||
MEDIA_TYPE_MUSIC,
|
MEDIA_TYPE_MUSIC,
|
||||||
|
MEDIA_TYPE_PLAYLIST,
|
||||||
SUPPORT_CLEAR_PLAYLIST,
|
SUPPORT_CLEAR_PLAYLIST,
|
||||||
SUPPORT_NEXT_TRACK,
|
SUPPORT_NEXT_TRACK,
|
||||||
SUPPORT_PAUSE,
|
SUPPORT_PAUSE,
|
||||||
@ -938,20 +939,35 @@ class SonosEntity(MediaPlayerDevice):
|
|||||||
"""
|
"""
|
||||||
Send the play_media command to the media player.
|
Send the play_media command to the media player.
|
||||||
|
|
||||||
|
If media_type is "playlist", media_id should be a Sonos
|
||||||
|
Playlist name. Otherwise, media_id should be a URI.
|
||||||
|
|
||||||
If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the queue.
|
If ATTR_MEDIA_ENQUEUE is True, add `media_id` to the queue.
|
||||||
"""
|
"""
|
||||||
if kwargs.get(ATTR_MEDIA_ENQUEUE):
|
if media_type == MEDIA_TYPE_MUSIC:
|
||||||
|
if kwargs.get(ATTR_MEDIA_ENQUEUE):
|
||||||
|
try:
|
||||||
|
self.soco.add_uri_to_queue(media_id)
|
||||||
|
except SoCoUPnPException:
|
||||||
|
_LOGGER.error(
|
||||||
|
'Error parsing media uri "%s", '
|
||||||
|
"please check it's a valid media resource "
|
||||||
|
"supported by Sonos",
|
||||||
|
media_id,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
self.soco.play_uri(media_id)
|
||||||
|
elif media_type == MEDIA_TYPE_PLAYLIST:
|
||||||
try:
|
try:
|
||||||
self.soco.add_uri_to_queue(media_id)
|
playlists = self.soco.get_sonos_playlists()
|
||||||
except SoCoUPnPException:
|
playlist = next(p for p in playlists if p.title == media_id)
|
||||||
_LOGGER.error(
|
self.soco.clear_queue()
|
||||||
'Error parsing media uri "%s", '
|
self.soco.add_to_queue(playlist)
|
||||||
"please check it's a valid media resource "
|
self.soco.play_from_queue(0)
|
||||||
"supported by Sonos",
|
except StopIteration:
|
||||||
media_id,
|
_LOGGER.error('Could not find a Sonos playlist named "%s"', media_id)
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
self.soco.play_uri(media_id)
|
_LOGGER.error('Sonos does not support a media type of "%s"', media_type)
|
||||||
|
|
||||||
@soco_error()
|
@soco_error()
|
||||||
def join(self, slaves):
|
def join(self, slaves):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user