Replace asyncio.wait_for with async_timeout in baf (#78445)
This commit is contained in:
parent
db44be7054
commit
b7e9fcb9fe
2 changed files with 6 additions and 2 deletions
|
@ -5,6 +5,7 @@ import asyncio
|
||||||
|
|
||||||
from aiobafi6 import Device, Service
|
from aiobafi6 import Device, Service
|
||||||
from aiobafi6.discovery import PORT
|
from aiobafi6.discovery import PORT
|
||||||
|
import async_timeout
|
||||||
|
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_IP_ADDRESS, Platform
|
from homeassistant.const import CONF_IP_ADDRESS, Platform
|
||||||
|
@ -34,7 +35,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
run_future = device.async_run()
|
run_future = device.async_run()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(device.async_wait_available(), timeout=RUN_TIMEOUT)
|
async with async_timeout.timeout(RUN_TIMEOUT):
|
||||||
|
await device.async_wait_available()
|
||||||
except asyncio.TimeoutError as ex:
|
except asyncio.TimeoutError as ex:
|
||||||
run_future.cancel()
|
run_future.cancel()
|
||||||
raise ConfigEntryNotReady(f"Timed out connecting to {ip_address}") from ex
|
raise ConfigEntryNotReady(f"Timed out connecting to {ip_address}") from ex
|
||||||
|
|
|
@ -7,6 +7,7 @@ from typing import Any
|
||||||
|
|
||||||
from aiobafi6 import Device, Service
|
from aiobafi6 import Device, Service
|
||||||
from aiobafi6.discovery import PORT
|
from aiobafi6.discovery import PORT
|
||||||
|
import async_timeout
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
|
@ -26,7 +27,8 @@ async def async_try_connect(ip_address: str) -> Device:
|
||||||
device = Device(Service(ip_addresses=[ip_address], port=PORT))
|
device = Device(Service(ip_addresses=[ip_address], port=PORT))
|
||||||
run_future = device.async_run()
|
run_future = device.async_run()
|
||||||
try:
|
try:
|
||||||
await asyncio.wait_for(device.async_wait_available(), timeout=RUN_TIMEOUT)
|
async with async_timeout.timeout(RUN_TIMEOUT):
|
||||||
|
await device.async_wait_available()
|
||||||
except asyncio.TimeoutError as ex:
|
except asyncio.TimeoutError as ex:
|
||||||
raise CannotConnect from ex
|
raise CannotConnect from ex
|
||||||
finally:
|
finally:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue