mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Use async with timeout (#85281)
This commit is contained in:
parent
9e68117a33
commit
1e78314638
@ -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):
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user