Skip to content

Commit

Permalink
fix(media_player): fix refresh handling based on websocket commands
Browse files Browse the repository at this point in the history
  • Loading branch information
alandtse committed Jan 15, 2020
1 parent 1ff35cf commit f795e78
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions custom_components/alexa_media/media_player.py
Expand Up @@ -216,14 +216,17 @@ async def _refresh_if_no_audiopush(already_refreshed=False):
if (
not already_refreshed
and seen_commands
and (
"PUSH_AUDIO_PLAYER_STATE" not in seen_commands
and "PUSH_MEDIA_CHANGE" not in seen_commands
and not (
"PUSH_AUDIO_PLAYER_STATE" in seen_commands
or "PUSH_MEDIA_CHANGE" in seen_commands
or "PUSH_MEDIA_PROGRESS_CHANGE" in seen_commands
)
):
# force refresh if player_state update not found, see #397
_LOGGER.debug(
"%s: No PUSH_AUDIO_PLAYER_STATE in %s; forcing refresh",
"%s: No PUSH_AUDIO_PLAYER_STATE/"
"PUSH_MEDIA_CHANGE/PUSH_MEDIA_PROGRESS_CHANGE in %s;"
"forcing refresh",
hide_email(email),
seen_commands,
)
Expand Down Expand Up @@ -715,16 +718,21 @@ async def async_update(self):
await self.refresh(
device, no_throttle=True # pylint: disable=unexpected-keyword-arg
)
websocket_enabled = self.hass.data[DATA_ALEXAMEDIA]["accounts"][email].get(
"websocket"
)
if (
self.state in [STATE_PLAYING]
and
# only enable polling if websocket not connected
(
not self.hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"]
or
# or if no PUSH_AUDIO_PLAYER_STATE
not seen_commands
or "PUSH_AUDIO_PLAYER_STATE" not in seen_commands
not websocket_enabled
or not seen_commands
or not (
"PUSH_AUDIO_PLAYER_STATE" in seen_commands
or "PUSH_MEDIA_CHANGE" in seen_commands
or "PUSH_MEDIA_PROGRESS_CHANGE" in seen_commands
)
)
):
self._should_poll = False # disable polling since manual update
Expand All @@ -746,7 +754,7 @@ async def async_update(self):
)
elif self._should_poll: # Not playing, one last poll
self._should_poll = False
if not (self.hass.data[DATA_ALEXAMEDIA]["accounts"][email]["websocket"]):
if not websocket_enabled:
_LOGGER.debug(
"Disabling polling and scheduling last update in"
" 300 seconds for %s",
Expand Down

0 comments on commit f795e78

Please sign in to comment.