Skip to content

Commit

Permalink
Remove retry logic
Browse files Browse the repository at this point in the history
  • Loading branch information
IceBotYT committed Jul 27, 2022
1 parent cfdee99 commit b27646b
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,7 @@ target/
src/test.py

# Output from various tests
*.txt
*.txt

# Snyk
.dccache
8 changes: 6 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = lacrosse_view
version = 0.0.7
version = 0.0.9
author = IceBotYT
author_email = [email protected]
description = Client for retrieving data from the La Crosse View cloud
Expand All @@ -25,4 +25,8 @@ install_requires =
pytz

[options.packages.find]
where = src
where = src

[options.package_data]
lacrosse_view =
*.typed
72 changes: 45 additions & 27 deletions src/lacrosse_view/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,47 @@
import datetime
import asyncio
from collections.abc import Coroutine, Callable


def _retry(
func: Any
) -> Any:
"""Handle query retries."""

async def wrapper(obj, *args, **kwargs) -> list[Sensor]:
"""Wrap all query functions."""
update_retries = 5
while update_retries > 0:
try:
result = await func(obj, *args, **kwargs)
break
except HTTPError as error:
update_retries -= 1
if update_retries == 0:
raise error
await asyncio.sleep(1)

return result

return wrapper
from functools import wraps


# def _retry() -> Callable[
# [
# Callable[
# [LaCrosse, str | Location | None, str | None, str | None, str | None],
# Coroutine[None, None, bool | list[Location] | list[Sensor]],
# ]
# ],
# Callable[[Any, Any, Any], bool | list[Location] | list[Sensor]],
# ]:
# """Handle query retries."""

# def _decorator(
# func: Callable[
# [LaCrosse, str | Location | None, str | None, str | None, str | None],
# Coroutine[None, None, bool | list[Location] | list[Sensor]],
# ]
# ) -> Callable[[Any, Any, Any], bool | list[Location] | list[Sensor]]:
# @wraps(func)
# async def wrapper(
# obj: Any, *args: Any, **kwargs: Any
# ) -> bool | list[Location] | list[Sensor]:
# """Wrap all query functions."""
# update_retries = 5
# while update_retries > 0:
# try:
# result = await func(obj, *args, **kwargs)
# break
# except HTTPError as error:
# update_retries -= 1
# if update_retries == 0:
# raise error
# await asyncio.sleep(1)

# return result

# return wrapper

# return _decorator


class LaCrosse:
Expand All @@ -43,7 +61,7 @@ class LaCrosse:
def __init__(self, websession: aiohttp.ClientSession | None = None):
self.websession = websession

@_retry
# @_retry()
async def login(self, email: str, password: str) -> bool:
"""Login to the LaCrosse API."""
login_url = (
Expand Down Expand Up @@ -77,7 +95,7 @@ async def login(self, email: str, password: str) -> bool:

return True

@_retry
# @_retry()
async def get_locations(self) -> list[Location]:
"""Get all locations."""
if self.token == "":
Expand Down Expand Up @@ -113,7 +131,7 @@ async def get_locations(self) -> list[Location]:
for location in data["items"]
]

@_retry
# @_retry()
async def get_sensors(
self,
location: Location,
Expand Down Expand Up @@ -236,7 +254,7 @@ async def get_sensors(

return devices

@_retry
# @_retry()
async def logout(self) -> bool:
"""Logout from the LaCrosse API."""
url = (
Expand Down

0 comments on commit b27646b

Please sign in to comment.