From b27646bc2c3e74a19f0e9f6532e90ab48767eb8b Mon Sep 17 00:00:00 2001 From: IceBotYT <34712694+IceBotYT@users.noreply.github.com> Date: Wed, 27 Jul 2022 08:54:50 -0400 Subject: [PATCH] Remove retry logic --- .gitignore | 5 ++- setup.cfg | 8 +++- src/lacrosse_view/__init__.py | 72 ++++++++++++++++++++++------------- 3 files changed, 55 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index 8207943..ed4d306 100644 --- a/.gitignore +++ b/.gitignore @@ -65,4 +65,7 @@ target/ src/test.py # Output from various tests -*.txt \ No newline at end of file +*.txt + +# Snyk +.dccache \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index fe30fc4..719ab8b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = lacrosse_view -version = 0.0.7 +version = 0.0.9 author = IceBotYT author_email = icebotyt@outlook.com description = Client for retrieving data from the La Crosse View cloud @@ -25,4 +25,8 @@ install_requires = pytz [options.packages.find] -where = src \ No newline at end of file +where = src + +[options.package_data] +lacrosse_view = + *.typed \ No newline at end of file diff --git a/src/lacrosse_view/__init__.py b/src/lacrosse_view/__init__.py index 1bb8369..2cc14d9 100644 --- a/src/lacrosse_view/__init__.py +++ b/src/lacrosse_view/__init__.py @@ -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: @@ -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 = ( @@ -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 == "": @@ -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, @@ -236,7 +254,7 @@ async def get_sensors( return devices - @_retry + # @_retry() async def logout(self) -> bool: """Logout from the LaCrosse API.""" url = (