Skip to content

Commit

Permalink
Check hourly rate limit on the Reolink servers
Browse files Browse the repository at this point in the history
  • Loading branch information
starkillerOG committed Nov 13, 2024
1 parent 38fd1c3 commit 4aea936
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion reolink_aio/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2746,9 +2746,18 @@ async def upload_firmware(self, channel: int | None = None, new_version: NewSoft

self._updating = True

# Check hourly rate limit on the Reolink servers
request_URL = "https://reolink.com/wp-json/reo-v2/download/firmware"
try:
await self.send_reolink_com(request_URL, expected_response_type="application/json", user_agent="reolink-aio-firmware")
except ApiError as err:
if err.rspCode == 429:
raise ApiError(f"Reolink firmware update server reached hourly rate limit: updating {self.camera_name(channel)} can be tried again in 1 hour") from err
raise err

# Download firmware file from Reolink Download Center
try:
response = await self.send_reolink_com(new_version.download_url, "application/octet-stream", user_agent="reolink-aio-firmware")
response = await self.send_reolink_com(new_version.download_url, expected_response_type="application/octet-stream")
except ApiError as err:
if err.rspCode == 429:
raise ApiError(f"Reolink firmware update server reached hourly rate limit: updating {self.camera_name(channel)} can be tried again in 1 hour") from err
Expand Down Expand Up @@ -5536,6 +5545,13 @@ async def send_reolink_com(
URL: str,
) -> dict[str, Any]: ...

@overload
async def send_reolink_com(
self,
URL: str,
expected_response_type: Literal["application/octet-stream"],
) -> aiohttp.ClientResponse: ...

@overload
async def send_reolink_com(
self,
Expand Down

0 comments on commit 4aea936

Please sign in to comment.