From cd3fc7c76d533b6ce673b9d281776a583995468b Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Fri, 17 Apr 2020 00:16:18 +0200 Subject: [PATCH] Fixes for Sonos media titles (#34311) --- .../components/sonos/media_player.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/sonos/media_player.py b/homeassistant/components/sonos/media_player.py index 33ca6265552..634952dcfdc 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -419,7 +419,7 @@ class SonosEntity(MediaPlayerDevice): if self._status in ("PAUSED_PLAYBACK", "STOPPED",): # Sonos can consider itself "paused" but without having media loaded # (happens if playing Spotify and via Spotify app you pick another device to play on) - if self._media_title is None: + if self.media_title is None: return STATE_IDLE return STATE_PAUSED if self._status in ("PLAYING", "TRANSITIONING"): @@ -614,12 +614,19 @@ class SonosEntity(MediaPlayerDevice): except (TypeError, KeyError, AttributeError): pass - # Radios without tagging can have part of the radio URI as title. - # Non-playing radios will not have a current title. In these cases we - # try to use the radio name instead. + # Non-playing radios will not have a current title. Radios without tagging + # can have part of the radio URI as title. In these cases we try to use the + # radio name instead. try: - if self._media_title in self._uri or self.state != STATE_PLAYING: - self._media_title = variables["enqueued_transport_uri_meta_data"].title + uri_meta_data = variables["enqueued_transport_uri_meta_data"] + if isinstance( + uri_meta_data, pysonos.data_structures.DidlAudioBroadcast + ) and ( + self.state != STATE_PLAYING + or self.soco.is_radio_uri(self._media_title) + or self._media_title in self._uri + ): + self._media_title = uri_meta_data.title except (TypeError, KeyError, AttributeError): pass