diff --git a/custom_components/norwegiantide/api.py b/custom_components/norwegiantide/api.py index f22c0eb..eb7260f 100644 --- a/custom_components/norwegiantide/api.py +++ b/custom_components/norwegiantide/api.py @@ -11,7 +11,6 @@ import pytz import aiohttp -import async_timeout import matplotlib.pyplot as plt import matplotlib.dates as mdates import numpy as np @@ -170,11 +169,12 @@ async def api_wrapper( ): """Get information from the API.""" try: - async with async_timeout.timeout(TIMEOUT, loop=asyncio.get_event_loop()): - if method == "get": - response = await self._session.get(url, headers=headers) - _LOGGER.debug(f"Response: {response.status} from URL: {url}") - return response + if method == "get": + response = await self._session.get( + url, headers=headers, timeout=aiohttp.ClientTimeout(total=TIMEOUT) + ) + _LOGGER.debug(f"Response: {response.status} from URL: {url}") + return response except asyncio.TimeoutError as exception: _LOGGER.error(f"Timeout fetching information from API")