diff --git a/homeassistant/components/hlk_sw16/config_flow.py b/homeassistant/components/hlk_sw16/config_flow.py index 83389472607..4920e1542d5 100644 --- a/homeassistant/components/hlk_sw16/config_flow.py +++ b/homeassistant/components/hlk_sw16/config_flow.py @@ -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): diff --git a/homeassistant/components/opentherm_gw/__init__.py b/homeassistant/components/opentherm_gw/__init__.py index 51071c9a0a1..aebf1e26c33 100644 --- a/homeassistant/components/opentherm_gw/__init__.py +++ b/homeassistant/components/opentherm_gw/__init__.py @@ -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( diff --git a/homeassistant/components/opentherm_gw/config_flow.py b/homeassistant/components/opentherm_gw/config_flow.py index ed9b62ff499..87a51021657 100644 --- a/homeassistant/components/opentherm_gw/config_flow.py +++ b/homeassistant/components/opentherm_gw/config_flow.py @@ -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): diff --git a/homeassistant/components/ping/binary_sensor.py b/homeassistant/components/ping/binary_sensor.py index 7500d9988af..c8b4ce5a204 100644 --- a/homeassistant/components/ping/binary_sensor.py +++ b/homeassistant/components/ping/binary_sensor.py @@ -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( diff --git a/homeassistant/components/squeezebox/config_flow.py b/homeassistant/components/squeezebox/config_flow.py index 1411b8bc782..bb175ee00be 100644 --- a/homeassistant/components/squeezebox/config_flow.py +++ b/homeassistant/components/squeezebox/config_flow.py @@ -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" diff --git a/homeassistant/components/upnp/__init__.py b/homeassistant/components/upnp/__init__.py index ac9fe19f4e7..7ddec4e3fbe 100644 --- a/homeassistant/components/upnp/__init__.py +++ b/homeassistant/components/upnp/__init__.py @@ -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: