From 12a7b64e64e0068241dfd284ea65202e7c3b59fb Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 4 Mar 2022 05:51:42 -0800 Subject: [PATCH] Add media source support to bluesound (#67563) --- .../components/bluesound/media_player.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/bluesound/media_player.py b/homeassistant/components/bluesound/media_player.py index 1995d7810a4..443d8faa5de 100644 --- a/homeassistant/components/bluesound/media_player.py +++ b/homeassistant/components/bluesound/media_player.py @@ -15,10 +15,15 @@ import async_timeout import voluptuous as vol import xmltodict +from homeassistant.components import media_source from homeassistant.components.media_player import PLATFORM_SCHEMA, MediaPlayerEntity +from homeassistant.components.media_player.browse_media import ( + async_process_play_media_url, +) from homeassistant.components.media_player.const import ( ATTR_MEDIA_ENQUEUE, MEDIA_TYPE_MUSIC, + SUPPORT_BROWSE_MEDIA, SUPPORT_CLEAR_PLAYLIST, SUPPORT_NEXT_TRACK, SUPPORT_PAUSE, @@ -800,7 +805,7 @@ class BluesoundPlayer(MediaPlayerEntity): if self.is_grouped and not self.is_master: return SUPPORT_VOLUME_STEP | SUPPORT_VOLUME_SET | SUPPORT_VOLUME_MUTE - supported = SUPPORT_CLEAR_PLAYLIST + supported = SUPPORT_CLEAR_PLAYLIST | SUPPORT_BROWSE_MEDIA if self._status.get("indexing", "0") == "0": supported = ( @@ -1029,6 +1034,12 @@ class BluesoundPlayer(MediaPlayerEntity): if self.is_grouped and not self.is_master: return + if media_source.is_media_source_id(media_id): + play_item = await media_source.async_resolve_media(self.hass, media_id) + media_id = play_item.url + + media_id = async_process_play_media_url(self.hass, media_id) + url = f"Play?url={media_id}" if kwargs.get(ATTR_MEDIA_ENQUEUE): @@ -1063,3 +1074,11 @@ class BluesoundPlayer(MediaPlayerEntity): if mute: return await self.send_bluesound_command("Volume?mute=1") return await self.send_bluesound_command("Volume?mute=0") + + async def async_browse_media(self, media_content_type=None, media_content_id=None): + """Implement the websocket media browsing helper.""" + return await media_source.async_browse_media( + self.hass, + media_content_id, + content_filter=lambda item: item.media_content_type.startswith("audio/"), + )