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."""
|
"""Config flow for HLK-SW16."""
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
from hlk_sw16 import create_hlk_sw16_connection
|
from hlk_sw16 import create_hlk_sw16_connection
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -35,7 +36,8 @@ async def connect_client(hass, user_input):
|
|||||||
reconnect_interval=DEFAULT_RECONNECT_INTERVAL,
|
reconnect_interval=DEFAULT_RECONNECT_INTERVAL,
|
||||||
keep_alive_interval=DEFAULT_KEEP_ALIVE_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):
|
async def validate_input(hass: HomeAssistant, user_input):
|
||||||
|
@ -3,6 +3,7 @@ import asyncio
|
|||||||
from datetime import date, datetime
|
from datetime import date, datetime
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
import pyotgw
|
import pyotgw
|
||||||
import pyotgw.vars as gw_vars
|
import pyotgw.vars as gw_vars
|
||||||
from serial import SerialException
|
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)
|
config_entry.add_update_listener(options_updated)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(
|
async with async_timeout.timeout(CONNECTION_TIMEOUT):
|
||||||
gateway.connect_and_subscribe(),
|
await gateway.connect_and_subscribe()
|
||||||
timeout=CONNECTION_TIMEOUT,
|
|
||||||
)
|
|
||||||
except (asyncio.TimeoutError, ConnectionError, SerialException) as ex:
|
except (asyncio.TimeoutError, ConnectionError, SerialException) as ex:
|
||||||
await gateway.cleanup()
|
await gateway.cleanup()
|
||||||
raise ConfigEntryNotReady(
|
raise ConfigEntryNotReady(
|
||||||
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
import pyotgw
|
import pyotgw
|
||||||
from pyotgw import vars as gw_vars
|
from pyotgw import vars as gw_vars
|
||||||
from serial import SerialException
|
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)
|
return status[gw_vars.OTGW].get(gw_vars.OTGW_ABOUT)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(
|
async with async_timeout.timeout(CONNECTION_TIMEOUT):
|
||||||
test_connection(),
|
await test_connection()
|
||||||
timeout=CONNECTION_TIMEOUT,
|
|
||||||
)
|
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
return self._show_form({"base": "timeout_connect"})
|
return self._show_form({"base": "timeout_connect"})
|
||||||
except (ConnectionError, SerialException):
|
except (ConnectionError, SerialException):
|
||||||
|
@ -8,6 +8,7 @@ import logging
|
|||||||
import re
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
from icmplib import NameLookupError, async_ping
|
from icmplib import NameLookupError, async_ping
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
@ -230,9 +231,8 @@ class PingDataSubProcess(PingData):
|
|||||||
close_fds=False, # required for posix_spawn
|
close_fds=False, # required for posix_spawn
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
out_data, out_error = await asyncio.wait_for(
|
async with async_timeout.timeout(self._count + PING_TIMEOUT):
|
||||||
pinger.communicate(), self._count + PING_TIMEOUT
|
out_data, out_error = await pinger.communicate()
|
||||||
)
|
|
||||||
|
|
||||||
if out_data:
|
if out_data:
|
||||||
_LOGGER.debug(
|
_LOGGER.debug(
|
||||||
|
@ -4,6 +4,7 @@ from http import HTTPStatus
|
|||||||
import logging
|
import logging
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
from pysqueezebox import Server, async_discover
|
from pysqueezebox import Server, async_discover
|
||||||
import voluptuous as vol
|
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
|
# no host specified, see if we can discover an unconfigured LMS server
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(self._discover(), timeout=TIMEOUT)
|
async with async_timeout.timeout(TIMEOUT):
|
||||||
|
await self._discover()
|
||||||
return await self.async_step_edit()
|
return await self.async_step_edit()
|
||||||
except asyncio.TimeoutError:
|
except asyncio.TimeoutError:
|
||||||
errors["base"] = "no_server_found"
|
errors["base"] = "no_server_found"
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import annotations
|
|||||||
import asyncio
|
import asyncio
|
||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
|
import async_timeout
|
||||||
from async_upnp_client.exceptions import UpnpConnectionError
|
from async_upnp_client.exceptions import UpnpConnectionError
|
||||||
|
|
||||||
from homeassistant.components import ssdp
|
from homeassistant.components import ssdp
|
||||||
@ -70,7 +71,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
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:
|
except asyncio.TimeoutError as err:
|
||||||
raise ConfigEntryNotReady(f"Device not discovered: {usn}") from err
|
raise ConfigEntryNotReady(f"Device not discovered: {usn}") from err
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user