Skip to content

Commit

Permalink
Merge pull request #52 from domwillcode/retry_get_all
Browse files Browse the repository at this point in the history
Add retry get_all
  • Loading branch information
gjohansson-ST authored Sep 4, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
2 parents 64e46f4 + 9c232b4 commit df72273
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions yalesmartalarmclient/client.py
Original file line number Diff line number Diff line change
@@ -53,16 +53,23 @@ def __init__(self, username: str, password: str, area_id: int = 1) -> None:
self.area_id = area_id
self.lock_api: YaleDoorManAPI = YaleDoorManAPI(auth=self.auth)

def get_all(self) -> dict[str, Any]:
"""DEBUG function to get full visibility from API for local testing."""
devices = self.auth.get_authenticated(self._ENDPOINT_DEVICES_STATUS)
mode = self.auth.get_authenticated(self._ENDPOINT_GET_MODE)
status = self.auth.get_authenticated(self._ENDPOINT_STATUS)
cycle = self.auth.get_authenticated(self._ENDPOINT_CYCLE)
online = self.auth.get_authenticated(self._ENDPOINT_ONLINE)
history = self.auth.get_authenticated(self._ENDPOINT_HISTORY)
panel_info = self.auth.get_authenticated(self._ENDPOINT_PANEL_INFO)
auth_check = self.auth.get_authenticated(self._ENDPOINT_CHECK)
def get_all(self, retry: int = 3) -> dict[str, Any]:
"""Get all information."""
try:
devices = self.auth.get_authenticated(self._ENDPOINT_DEVICES_STATUS)
mode = self.auth.get_authenticated(self._ENDPOINT_GET_MODE)
status = self.auth.get_authenticated(self._ENDPOINT_STATUS)
cycle = self.auth.get_authenticated(self._ENDPOINT_CYCLE)
online = self.auth.get_authenticated(self._ENDPOINT_ONLINE)
history = self.auth.get_authenticated(self._ENDPOINT_HISTORY)
panel_info = self.auth.get_authenticated(self._ENDPOINT_PANEL_INFO)
auth_check = self.auth.get_authenticated(self._ENDPOINT_CHECK)
except Exception as error:
_LOGGER.debug("Retry %d on get_all function", 4 - retry)
if retry > 0:
time.sleep(5)
return self.get_all(retry - 1)
raise error

return {
"DEVICES": devices["data"],

0 comments on commit df72273

Please sign in to comment.