mirror of
https://github.com/esphome/aioesphomeapi.git
synced 2025-02-17 01:51:23 +01:00
Change to event
This commit is contained in:
parent
49db2b021d
commit
d17509be5b
@ -452,13 +452,14 @@ class APIClient:
|
|||||||
) -> Callable[[], None]:
|
) -> Callable[[], None]:
|
||||||
self._check_authenticated()
|
self._check_authenticated()
|
||||||
|
|
||||||
fut = asyncio.get_event_loop().create_future()
|
event = asyncio.Event()
|
||||||
|
|
||||||
def on_msg(msg: message.Message) -> None:
|
def on_msg(msg: message.Message) -> None:
|
||||||
if isinstance(msg, BluetoothDeviceConnectionResponse):
|
if isinstance(msg, BluetoothDeviceConnectionResponse):
|
||||||
resp = BluetoothDeviceConnection.from_pb(msg)
|
resp = BluetoothDeviceConnection.from_pb(msg)
|
||||||
if address == resp.address:
|
if address == resp.address:
|
||||||
on_bluetooth_connection_state(resp.connected, resp.mtu, resp.error)
|
on_bluetooth_connection_state(resp.connected, resp.mtu, resp.error)
|
||||||
|
event.set()
|
||||||
|
|
||||||
assert self._connection is not None
|
assert self._connection is not None
|
||||||
await self._connection.send_message_callback_response(
|
await self._connection.send_message_callback_response(
|
||||||
@ -471,7 +472,7 @@ class APIClient:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
async with async_timeout.timeout(timeout):
|
async with async_timeout.timeout(timeout):
|
||||||
await fut
|
await event.wait()
|
||||||
except asyncio.TimeoutError as err:
|
except asyncio.TimeoutError as err:
|
||||||
raise TimeoutAPIError("Timeout waiting for connect response") from err
|
raise TimeoutAPIError("Timeout waiting for connect response") from err
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user