diff --git a/custom_components/oilfox/OilFox.py b/custom_components/oilfox/OilFox.py index 3f1e27e..3e1daf2 100644 --- a/custom_components/oilfox/OilFox.py +++ b/custom_components/oilfox/OilFox.py @@ -2,6 +2,7 @@ import time import logging import aiohttp +from aiohttp import ClientTimeout _LOGGER = logging.getLogger(__name__) @@ -10,7 +11,7 @@ class OilFox: """OilFox Python Class""" # https://github.com/foxinsights/customer-api - TIMEOUT = 15 + TIMEOUT = 30 TOKEN_VALID = 900 hwid = None password = None @@ -59,12 +60,12 @@ async def update_stats(self): if not_error: headers = {"Authorization": "Bearer " + self.access_token} - async with aiohttp.ClientSession(timeout=self.TIMEOUT) as session: + async with aiohttp.ClientSession( + timeout=ClientTimeout(total=self.TIMEOUT) + ) as session: try: async with session.get( - self.deviceUrl + self.hwid, - headers=headers, - timeout=self.TIMEOUT, + self.deviceUrl + self.hwid, headers=headers ) as response: if response.status == 200: self.state = await response.json() @@ -84,9 +85,11 @@ async def get_tokens(self): "email": self.email, } - async with aiohttp.ClientSession() as session: + async with aiohttp.ClientSession( + timeout=ClientTimeout(total=self.TIMEOUT) + ) as session: async with session.post( - self.loginUrl, headers=headers, json=json_data, timeout=self.TIMEOUT + self.loginUrl, headers=headers, json=json_data ) as response: if response.status == 200: json_response = await response.json() @@ -103,10 +106,10 @@ async def get_access_token(self): data = { "refresh_token": self.refresh_token, } - async with aiohttp.ClientSession() as session: - async with session.post( - self.tokenUrl, data=data, timeout=self.TIMEOUT - ) as response: + async with aiohttp.ClientSession( + timeout=ClientTimeout(total=self.TIMEOUT) + ) as session: + async with session.post(self.tokenUrl, data=data) as response: if response.status == 200: json_response = await response.json() self.access_token = json_response["access_token"] diff --git a/custom_components/oilfox/manifest.json b/custom_components/oilfox/manifest.json index a218d0d..908fe8e 100644 --- a/custom_components/oilfox/manifest.json +++ b/custom_components/oilfox/manifest.json @@ -14,5 +14,5 @@ ], "iot_class": "cloud_polling", "loggers": ["oilfox_component"], - "version": "0.1.14-beta" + "version": "0.1.16" }