mirror of
https://github.com/home-assistant/core.git
synced 2025-07-29 16:17:20 +00:00
Use async_timeout in integrations (#88697)
This commit is contained in:
parent
ee8f746808
commit
753c790a25
@ -1,6 +1,7 @@
|
||||
"""Config flow for HLK-SW16."""
|
||||
import asyncio
|
||||
|
||||
import async_timeout
|
||||
from hlk_sw16 import create_hlk_sw16_connection
|
||||
import voluptuous as vol
|
||||
|
||||
@ -35,7 +36,8 @@ async def connect_client(hass, user_input):
|
||||
reconnect_interval=DEFAULT_RECONNECT_INTERVAL,
|
||||
keep_alive_interval=DEFAULT_KEEP_ALIVE_INTERVAL,
|
||||
)
|
||||
return await asyncio.wait_for(client_aw, timeout=CONNECTION_TIMEOUT)
|
||||
async with async_timeout.timeout(CONNECTION_TIMEOUT):
|
||||
return await client_aw
|
||||
|
||||
|
||||
async def validate_input(hass: HomeAssistant, user_input):
|
||||
|
@ -3,6 +3,7 @@ import asyncio
|
||||
from datetime import date, datetime
|
||||
import logging
|
||||
|
||||
import async_timeout
|
||||
import pyotgw
|
||||
import pyotgw.vars as gw_vars
|
||||
from serial import SerialException
|
||||
@ -112,10 +113,8 @@ async def async_setup_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> b
|
||||
config_entry.add_update_listener(options_updated)
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
gateway.connect_and_subscribe(),
|
||||
timeout=CONNECTION_TIMEOUT,
|
||||
)
|
||||
async with async_timeout.timeout(CONNECTION_TIMEOUT):
|
||||
await gateway.connect_and_subscribe()
|
||||
except (asyncio.TimeoutError, ConnectionError, SerialException) as ex:
|
||||
await gateway.cleanup()
|
||||
raise ConfigEntryNotReady(
|
||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
|
||||
import async_timeout
|
||||
import pyotgw
|
||||
from pyotgw import vars as gw_vars
|
||||
from serial import SerialException
|
||||
@ -68,10 +69,8 @@ class OpenThermGwConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
return status[gw_vars.OTGW].get(gw_vars.OTGW_ABOUT)
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(
|
||||
test_connection(),
|
||||
timeout=CONNECTION_TIMEOUT,
|
||||
)
|
||||
async with async_timeout.timeout(CONNECTION_TIMEOUT):
|
||||
await test_connection()
|
||||
except asyncio.TimeoutError:
|
||||
return self._show_form({"base": "timeout_connect"})
|
||||
except (ConnectionError, SerialException):
|
||||
|
@ -8,6 +8,7 @@ import logging
|
||||
import re
|
||||
from typing import Any
|
||||
|
||||
import async_timeout
|
||||
from icmplib import NameLookupError, async_ping
|
||||
import voluptuous as vol
|
||||
|
||||
@ -230,9 +231,8 @@ class PingDataSubProcess(PingData):
|
||||
close_fds=False, # required for posix_spawn
|
||||
)
|
||||
try:
|
||||
out_data, out_error = await asyncio.wait_for(
|
||||
pinger.communicate(), self._count + PING_TIMEOUT
|
||||
)
|
||||
async with async_timeout.timeout(self._count + PING_TIMEOUT):
|
||||
out_data, out_error = await pinger.communicate()
|
||||
|
||||
if out_data:
|
||||
_LOGGER.debug(
|
||||
|
@ -4,6 +4,7 @@ from http import HTTPStatus
|
||||
import logging
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import async_timeout
|
||||
from pysqueezebox import Server, async_discover
|
||||
import voluptuous as vol
|
||||
|
||||
@ -130,7 +131,8 @@ class SqueezeboxConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
|
||||
# no host specified, see if we can discover an unconfigured LMS server
|
||||
try:
|
||||
await asyncio.wait_for(self._discover(), timeout=TIMEOUT)
|
||||
async with async_timeout.timeout(TIMEOUT):
|
||||
await self._discover()
|
||||
return await self.async_step_edit()
|
||||
except asyncio.TimeoutError:
|
||||
errors["base"] = "no_server_found"
|
||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
||||
import asyncio
|
||||
from datetime import timedelta
|
||||
|
||||
import async_timeout
|
||||
from async_upnp_client.exceptions import UpnpConnectionError
|
||||
|
||||
from homeassistant.components import ssdp
|
||||
@ -70,7 +71,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
)
|
||||
|
||||
try:
|
||||
await asyncio.wait_for(device_discovered_event.wait(), timeout=10)
|
||||
async with async_timeout.timeout(10):
|
||||
await device_discovered_event.wait()
|
||||
except asyncio.TimeoutError as err:
|
||||
raise ConfigEntryNotReady(f"Device not discovered: {usn}") from err
|
||||
finally:
|
||||
|
Loading…
x
Reference in New Issue
Block a user