diff --git a/homewizard_energy/__init__.py b/homewizard_energy/__init__.py index 5053bfb..34c94d9 100644 --- a/homewizard_energy/__init__.py +++ b/homewizard_energy/__init__.py @@ -27,10 +27,10 @@ async def has_v2_api(host: str, websession: ClientSession | None = None) -> bool # v2 api is https only and returns a 401 Unauthorized when no key provided, # no connection can be made if the device is not v2 url = f"https://{host}/api" - res = await websession.get(url, ssl=False, raise_for_status=False, timeout=5) - res.close() - - return res.status == 401 + async with asyncio.timeout(5.0): + res = await websession.get(url, ssl=False, raise_for_status=False) + res.close() + return res.status == 401 except Exception: # pylint: disable=broad-except # all other status/exceptions means the device is not v2 or not reachable at this time return False