Change to event

This commit is contained in:
Jesse Hills 2022-09-28 12:52:36 +13:00
parent 49db2b021d
commit d17509be5b
No known key found for this signature in database
GPG Key ID: BEAAE804EFD8E83A
1 changed files with 3 additions and 2 deletions

View File

@ -452,13 +452,14 @@ class APIClient:
) -> Callable[[], None]:
self._check_authenticated()
fut = asyncio.get_event_loop().create_future()
event = asyncio.Event()
def on_msg(msg: message.Message) -> None:
if isinstance(msg, BluetoothDeviceConnectionResponse):
resp = BluetoothDeviceConnection.from_pb(msg)
if address == resp.address:
on_bluetooth_connection_state(resp.connected, resp.mtu, resp.error)
event.set()
assert self._connection is not None
await self._connection.send_message_callback_response(
@ -471,7 +472,7 @@ class APIClient:
try:
async with async_timeout.timeout(timeout):
await fut
await event.wait()
except asyncio.TimeoutError as err:
raise TimeoutAPIError("Timeout waiting for connect response") from err