Fix async_timeout deprecation warning (#94594)

* Fix async_timeout deprecation warning

* Combine async with
This commit is contained in:
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

View File

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