Fix async_timeout deprecation warning (#94594)

* Fix async_timeout deprecation warning

* Combine async with
pull/94611/head
Michael Hansen 2023-06-14 14:26:24 -05:00 committed by GitHub
parent 7fbeac9bbe
commit 5c3ec8774d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 15 deletions

View File

@ -53,23 +53,24 @@ async def load_wyoming_info(
for _ in range(retries + 1):
try:
async with AsyncTcpClient(host, port) as client:
with async_timeout.timeout(timeout):
# Describe -> Info
await client.write_event(Describe().event())
while True:
event = await client.read_event()
if event is None:
raise WyomingError(
"Connection closed unexpectedly",
)
async with AsyncTcpClient(host, port) as client, async_timeout.timeout(
timeout
):
# Describe -> Info
await client.write_event(Describe().event())
while True:
event = await client.read_event()
if event is None:
raise WyomingError(
"Connection closed unexpectedly",
)
if Info.is_type(event.type):
wyoming_info = Info.from_event(event)
break # while
if Info.is_type(event.type):
wyoming_info = Info.from_event(event)
break # while
if wyoming_info is not None:
break # for
if wyoming_info is not None:
break # for
except (asyncio.TimeoutError, OSError, WyomingError):
# Sleep and try again
await asyncio.sleep(retry_wait)