Skip to content

Commit 7dd5984

Browse files
committed
Wait upt to a second instead of erroring on rate limiter exceed
1 parent 22241fc commit 7dd5984

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

roborock/web_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class RoborockApiClient:
6262
Rate(40, Duration.DAY),
6363
]
6464

65-
_login_limiter = Limiter(_LOGIN_RATES)
65+
_login_limiter = Limiter(_LOGIN_RATES, max_delay=1000)
6666
_home_data_limiter = Limiter(_HOME_DATA_RATES)
6767

6868
def __init__(
@@ -205,7 +205,7 @@ async def add_device(self, user_data: UserData, s: str, t: str) -> dict:
205205

206206
async def request_code(self) -> None:
207207
try:
208-
self._login_limiter.try_acquire("login")
208+
await self._login_limiter.try_acquire_async("login")
209209
except BucketFullException as ex:
210210
_LOGGER.info(ex.meta_info)
211211
raise RoborockRateLimit("Reached maximum requests for login. Please try again later.") from ex
@@ -239,7 +239,7 @@ async def request_code_v4(self) -> None:
239239
_LOGGER.info("No country code or country found, trying old version of request code.")
240240
return await self.request_code()
241241
try:
242-
self._login_limiter.try_acquire("login")
242+
await self._login_limiter.try_acquire_async("login")
243243
except BucketFullException as ex:
244244
_LOGGER.info(ex.meta_info)
245245
raise RoborockRateLimit("Reached maximum requests for login. Please try again later.") from ex
@@ -367,7 +367,7 @@ async def code_login_v4(
367367

368368
async def pass_login(self, password: str) -> UserData:
369369
try:
370-
self._login_limiter.try_acquire("login")
370+
await self._login_limiter.try_acquire_async("login")
371371
except BucketFullException as ex:
372372
_LOGGER.info(ex.meta_info)
373373
raise RoborockRateLimit("Reached maximum requests for login. Please try again later.") from ex

0 commit comments

Comments
 (0)