Skip to content

Commit

Permalink
httpx set timeout to 30s
Browse files Browse the repository at this point in the history
  • Loading branch information
leeyuentuen committed Jan 2, 2024
1 parent 2fead1c commit b30ce69
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 4 additions & 3 deletions custom_components/polestar_api/pypolestar/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import httpx

from .const import HTTPX_TIMEOUT
from .exception import PolestarAuthException

_LOGGER = logging.getLogger(__name__)
Expand Down Expand Up @@ -46,7 +47,7 @@ async def get_token(self, refresh=False) -> None:
"operationName": operationName,
"variables": json.dumps({"token": token}),
}
result = await self._client_session.get("https://pc-api.polestar.com/eu-north-1/auth/", params=params, headers=headers)
result = await self._client_session.get("https://pc-api.polestar.com/eu-north-1/auth/", params=params, headers=headers, timeout=HTTPX_TIMEOUT)
self.latest_call_code = result.status_code
resultData = result.json()
if result.status_code != 200 or ("errors" in resultData and len(resultData["errors"])):
Expand Down Expand Up @@ -97,7 +98,7 @@ async def _get_code(self) -> None:
code = result.next_request.url.params.get('code')

# sign-in-callback
result = await self._client_session.get(result.next_request.url)
result = await self._client_session.get(result.next_request.url, timeout=HTTPX_TIMEOUT)
self.latest_call_code = result.status_code

if result.status_code != 200:
Expand All @@ -116,7 +117,7 @@ async def _get_resume_path(self):
"client_id": "polmystar",
"redirect_uri": "https://www.polestar.com/sign-in-callback"
}
result = await self._client_session.get("https://polestarid.eu.polestar.com/as/authorization.oauth2", params=params)
result = await self._client_session.get("https://polestarid.eu.polestar.com/as/authorization.oauth2", params=params, timeout=HTTPX_TIMEOUT)
if result.status_code != 303:
raise PolestarAuthException("Error getting resume path ", result.status_code)
return result.next_request.url.params
2 changes: 2 additions & 0 deletions custom_components/polestar_api/pypolestar/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
CAR_INFO_DATA = "getConsumerCarsV2"
ODO_METER_DATA = "getOdometerData"
BATTERY_DATA = "getBatteryData"

HTTPX_TIMEOUT = 30

0 comments on commit b30ce69

Please sign in to comment.