Skip to content

Commit

Permalink
fix: force refresh on active media players on push
Browse files Browse the repository at this point in the history
Certain push activities will clear the media state so must be checked.
closes #617
  • Loading branch information
alandtse committed Apr 2, 2020
1 parent 774ebd8 commit 3556360
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions custom_components/alexa_media/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -793,6 +793,7 @@ async def ws_handler(message_obj):
and json_payload["key"]["entryId"].find("#") != -1
):
serial = (json_payload["key"]["entryId"]).split("#")[2]
json_payload["key"]["serialNumber"] = serial
else:
serial = None
if command == "PUSH_ACTIVITY":
Expand Down
15 changes: 15 additions & 0 deletions custom_components/alexa_media/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
if event.data["queue_state"]
else None
)
elif "push_activity" in event.data:
event_serial = (
event.data.get("push_activity", {}).get("key", {}).get("serialNumber")
)
if not event_serial:
return
self.available = True
Expand Down Expand Up @@ -346,6 +350,17 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
if self.hass and self.async_schedule_update_ha_state:
self.async_schedule_update_ha_state()
await _refresh_if_no_audiopush(already_refreshed)
elif "push_activity" in event.data:
if self.state in {STATE_IDLE, STATE_PAUSED, STATE_PLAYING}:
_LOGGER.debug(
"%s checking for potential state update due to push activity on %s",
self.name,
hide_serial(event_serial),
)
# allow delay before trying to refresh to avoid http 400 errors
await asyncio.sleep(2)
await self.async_update()
already_refreshed = True
if "queue_state" in event.data:
queue_state = event.data["queue_state"]
if event_serial == self.device_serial_number:
Expand Down

0 comments on commit 3556360

Please sign in to comment.