mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Fix async_timeout deprecation warning (#94594)
* Fix async_timeout deprecation warning * Combine async with
This commit is contained in:
parent
7fbeac9bbe
commit
5c3ec8774d
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user