From e47f3999fdd67d420ece0579b0ff20281f3d3279 Mon Sep 17 00:00:00 2001 From: Anders Melchiorsen Date: Tue, 14 Apr 2020 22:23:38 +0200 Subject: [PATCH] Fixes for Sonos media titles --- .../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 33ca62655520b1..634952dcfdcdb8 100644 --- a/homeassistant/components/sonos/media_player.py +++ b/homeassistant/components/sonos/media_player.py @@ -419,7 +419,7 @@ def state(self): 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 @@ def update_media_radio(self, variables, track_info): 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