Use async with timeout (#85281)

This commit is contained in:
Paulus Schoutsen 2023-01-06 01:43:56 -05:00 committed by GitHub
parent 9e68117a33
commit 1e78314638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 3 additions and 3 deletions

View File

@ -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):

View File

@ -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()

View File

@ -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