From 1e783146380542a96feb0b61c2320eb2505be19d Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 6 Jan 2023 01:43:56 -0500 Subject: [PATCH] Use async with timeout (#85281) --- homeassistant/components/hue/bridge.py | 2 +- homeassistant/components/hue/v1/light.py | 2 +- homeassistant/components/prusalink/__init__.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/hue/bridge.py b/homeassistant/components/hue/bridge.py index 625a623105f..c39fbed180c 100644 --- a/homeassistant/components/hue/bridge.py +++ b/homeassistant/components/hue/bridge.py @@ -72,7 +72,7 @@ class HueBridge: async def async_initialize_bridge(self) -> bool: """Initialize Connection with the Hue API.""" try: - with async_timeout.timeout(10): + async with async_timeout.timeout(10): await self.api.initialize() except (LinkButtonNotPressed, Unauthorized): diff --git a/homeassistant/components/hue/v1/light.py b/homeassistant/components/hue/v1/light.py index e840835764b..f0ba0dbac23 100644 --- a/homeassistant/components/hue/v1/light.py +++ b/homeassistant/components/hue/v1/light.py @@ -262,7 +262,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities): async def async_safe_fetch(bridge, fetch_method): """Safely fetch data.""" try: - with async_timeout.timeout(4): + async with async_timeout.timeout(4): return await bridge.async_request_call(fetch_method) except aiohue.Unauthorized as err: await bridge.handle_unauthorized_error() diff --git a/homeassistant/components/prusalink/__init__.py b/homeassistant/components/prusalink/__init__.py index 0172a237da8..70853623f0e 100644 --- a/homeassistant/components/prusalink/__init__.py +++ b/homeassistant/components/prusalink/__init__.py @@ -77,7 +77,7 @@ class PrusaLinkUpdateCoordinator(DataUpdateCoordinator, Generic[T], ABC): async def _async_update_data(self) -> T: """Update the data.""" try: - with async_timeout.timeout(5): + async with async_timeout.timeout(5): data = await self._fetch_data() except InvalidAuth: raise UpdateFailed("Invalid authentication") from None