Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace asyncio.wait_for with async_timeout in baf #78445

Merged
merged 1 commit into from Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion homeassistant/components/baf/__init__.py
Expand Up @@ -5,6 +5,7 @@

from aiobafi6 import Device, Service
from aiobafi6.discovery import PORT
import async_timeout

from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_IP_ADDRESS, Platform
Expand Down Expand Up @@ -34,7 +35,8 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
run_future = device.async_run()

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:
run_future.cancel()
raise ConfigEntryNotReady(f"Timed out connecting to {ip_address}") from ex
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/baf/config_flow.py
Expand Up @@ -7,6 +7,7 @@

from aiobafi6 import Device, Service
from aiobafi6.discovery import PORT
import async_timeout
import voluptuous as vol

from homeassistant import config_entries
Expand All @@ -26,7 +27,8 @@ async def async_try_connect(ip_address: str) -> Device:
device = Device(Service(ip_addresses=[ip_address], port=PORT))
run_future = device.async_run()
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:
raise CannotConnect from ex
finally:
Expand Down