From 9e0645caeb38d375b784cfb1fa44600f1754a91c Mon Sep 17 00:00:00 2001 From: chises Date: Wed, 31 Jan 2024 20:55:36 +0100 Subject: [PATCH] fix for HA 2024.1.6 and aiohttp --- custom_components/oilfox/OilFox.py | 15 ++++++++++----- custom_components/oilfox/UpdateCoordinator.py | 2 +- custom_components/oilfox/manifest.json | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/custom_components/oilfox/OilFox.py b/custom_components/oilfox/OilFox.py index 07bd004..968edf5 100644 --- a/custom_components/oilfox/OilFox.py +++ b/custom_components/oilfox/OilFox.py @@ -66,16 +66,18 @@ 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=aiohttp.ClientTimeout(self.TIMEOUT) + ) as session: try: async with session.get( self.device_url + self.hwid, headers=headers, - timeout=self.TIMEOUT, + timeout=aiohttp.ClientTimeout(self.TIMEOUT), ) as response: if response.status == 200: self.state = await response.json() - except asyncio.TimeoutError as err: + except asyncio.TimeoutError: raise ConfigEntryNotReady( # noqa: TRY200 f"Update values failed because of http timeout (waited for {self.TIMEOUT} s)!" ) @@ -101,7 +103,10 @@ async def get_tokens(self): } async with aiohttp.ClientSession() as session, session.post( - self.login_url, headers=headers, json=json_data, timeout=self.TIMEOUT + self.login_url, + headers=headers, + json=json_data, + timeout=aiohttp.ClientTimeout(self.TIMEOUT), ) as response: if response.status == 200: json_response = await response.json() @@ -121,7 +126,7 @@ async def get_access_token(self): "refresh_token": self.refresh_token, } async with aiohttp.ClientSession() as session, session.post( - self.token_url, data=data, timeout=self.TIMEOUT + self.token_url, data=data, timeout=aiohttp.ClientTimeout(self.TIMEOUT) ) as response: _LOGGER.debug("Get Access Token:%s", response.status) if response.status == 200: diff --git a/custom_components/oilfox/UpdateCoordinator.py b/custom_components/oilfox/UpdateCoordinator.py index 7ce81fb..9228985 100644 --- a/custom_components/oilfox/UpdateCoordinator.py +++ b/custom_components/oilfox/UpdateCoordinator.py @@ -29,7 +29,7 @@ def __init__( hass, _LOGGER, name=DOMAIN, - update_interval=timedelta(minutes=1), + update_interval=timedelta(minutes=15), ) async def _async_update_data(self) -> None: diff --git a/custom_components/oilfox/manifest.json b/custom_components/oilfox/manifest.json index 9e94d3b..c08f390 100644 --- a/custom_components/oilfox/manifest.json +++ b/custom_components/oilfox/manifest.json @@ -8,6 +8,6 @@ "iot_class": "cloud_polling", "issue_tracker": "https://github.com/chises/ha-oilfox/issues", "loggers": ["oilfox_component"], - "requirements": ["aiohttp==3.9.1"], - "version": "1.0.0-alpha" + "requirements": ["aiohttp"], + "version": "1.0.1-alpha" }