Skip to content

Commit

Permalink
automatically increase polling interval by 1/4s at a time when being …
Browse files Browse the repository at this point in the history
…throttled, don't update data if we get throttled
  • Loading branch information
snicker committed Feb 6, 2022
1 parent 407f7dd commit 284bd6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/zwift/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"documentation": "https://github.com/snicker/zwift_hass/blob/master/README.md",
"requirements": ["zwift-client==0.2.0"],
"dependencies": [],
"version": "3.2.4",
"version": "3.2.5",
"codeowners": ["@snicker"],
"iot_class": "cloud_polling"
}
7 changes: 6 additions & 1 deletion custom_components/zwift/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,17 +387,22 @@ def update(self):
})
online_player.update(player_profile)
self.players[player_id].player_profile = online_player
self.players[player_id].data = data
except RequestException as e:
if '401' in str(e):
self._client = None
_LOGGER.warning('Zwift credentials are wrong or expired')
elif '404' in str(e):
_LOGGER.warning('Upstream Zwift 404 - will try later')
elif '429' in str(e):
current_interval = self.online_update_interval
new_interval = self.online_update_interval + timedelta(seconds=0.25)
self.online_update_interval = new_interval
_LOGGER.warning('Upstream request throttling 429 - known issue, increasing interval from {}s to {}s')
else:
_LOGGER.exception('something went wrong in Zwift python library - {} while updating zwift sensor for player {}'.format(str(e), player_id))
except Exception as e:
_LOGGER.exception('something went major wrong while updating zwift sensor for player {}'.format(player_id))
self.players[player_id].data = data
_LOGGER.debug("dispatching zwift data update for player {}".format(player_id))
dispatcher_send(self.hass, SIGNAL_ZWIFT_UPDATE.format(player_id=player_id))

0 comments on commit 284bd6e

Please sign in to comment.