Properly resolve media_source URLs for Sonos announcements (#92154)

Properly resolve media_source URLs for Sonos announcements
This commit is contained in:
jjlawren 2023-04-27 22:51:51 -05:00 committed by GitHub
parent 9d0dd0b784
commit 4ce1106243
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -506,13 +506,23 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
If media_type is "playlist", media_id should be a Sonos If media_type is "playlist", media_id should be a Sonos
Playlist name. Otherwise, media_id should be a URI. Playlist name. Otherwise, media_id should be a URI.
""" """
is_radio = False
if media_source.is_media_source_id(media_id):
is_radio = media_id.startswith("media-source://radio_browser/")
media_type = MediaType.MUSIC
media = await media_source.async_resolve_media(
self.hass, media_id, self.entity_id
)
media_id = async_process_play_media_url(self.hass, media.url)
if kwargs.get(ATTR_MEDIA_ANNOUNCE): if kwargs.get(ATTR_MEDIA_ANNOUNCE):
volume = kwargs.get("extra", {}).get("volume") volume = kwargs.get("extra", {}).get("volume")
_LOGGER.debug("Playing %s using websocket audioclip", media_id) _LOGGER.debug("Playing %s using websocket audioclip", media_id)
try: try:
assert self.speaker.websocket assert self.speaker.websocket
response, _ = await self.speaker.websocket.play_clip( response, _ = await self.speaker.websocket.play_clip(
media_id, async_process_play_media_url(self.hass, media_id),
volume=volume, volume=volume,
) )
except SonosWebsocketError as exc: except SonosWebsocketError as exc:
@ -526,16 +536,6 @@ class SonosMediaPlayerEntity(SonosEntity, MediaPlayerEntity):
media_type = spotify.resolve_spotify_media_type(media_type) media_type = spotify.resolve_spotify_media_type(media_type)
media_id = spotify.spotify_uri_from_media_browser_url(media_id) media_id = spotify.spotify_uri_from_media_browser_url(media_id)
is_radio = False
if media_source.is_media_source_id(media_id):
is_radio = media_id.startswith("media-source://radio_browser/")
media_type = MediaType.MUSIC
media = await media_source.async_resolve_media(
self.hass, media_id, self.entity_id
)
media_id = media.url
await self.hass.async_add_executor_job( await self.hass.async_add_executor_job(
partial(self._play_media, media_type, media_id, is_radio, **kwargs) partial(self._play_media, media_type, media_id, is_radio, **kwargs)
) )