Optimize Sonos current playing state (#43517)

pull/43541/head
Anders Melchiorsen 2020-11-22 22:16:03 +01:00 committed by GitHub
parent 498654a1e0
commit 9ffdec63cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 3 deletions

View File

@ -724,8 +724,13 @@ class SonosEntity(MediaPlayerEntity):
def update_media(self, event=None):
"""Update information about currently playing media."""
transport_info = self.soco.get_current_transport_info()
new_status = transport_info.get("current_transport_state")
variables = event and event.variables
if variables:
new_status = variables["transport_state"]
else:
transport_info = self.soco.get_current_transport_info()
new_status = transport_info["current_transport_state"]
# Ignore transitions, we should get the target state soon
if new_status == "TRANSITIONING":
@ -760,7 +765,6 @@ class SonosEntity(MediaPlayerEntity):
self._media_title = track_info.get("title")
if self.soco.is_radio_uri(track_info["uri"]):
variables = event and event.variables
self.update_media_radio(variables, track_info)
else:
self.update_media_music(update_position, track_info)