diff --git a/custom_components/polestar_api/pypolestar/auth.py b/custom_components/polestar_api/pypolestar/auth.py index 0766c37..a6bdf6f 100644 --- a/custom_components/polestar_api/pypolestar/auth.py +++ b/custom_components/polestar_api/pypolestar/auth.py @@ -4,6 +4,7 @@ import httpx +from .const import HTTPX_TIMEOUT from .exception import PolestarAuthException _LOGGER = logging.getLogger(__name__) @@ -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"])): @@ -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: @@ -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 diff --git a/custom_components/polestar_api/pypolestar/const.py b/custom_components/polestar_api/pypolestar/const.py index f807541..b72fafe 100644 --- a/custom_components/polestar_api/pypolestar/const.py +++ b/custom_components/polestar_api/pypolestar/const.py @@ -3,3 +3,5 @@ CAR_INFO_DATA = "getConsumerCarsV2" ODO_METER_DATA = "getOdometerData" BATTERY_DATA = "getBatteryData" + +HTTPX_TIMEOUT = 30