mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Update esphome bluetooth client for python 3.11 (#86480)
This commit is contained in:
parent
e15aaf2853
commit
978aafdd09
@ -68,15 +68,16 @@ def verify_connected(func: _WrapFuncType) -> _WrapFuncType:
|
|||||||
)
|
)
|
||||||
if not disconnected_event:
|
if not disconnected_event:
|
||||||
raise BleakError("Not connected")
|
raise BleakError("Not connected")
|
||||||
task = asyncio.create_task(func(self, *args, **kwargs))
|
action_task = asyncio.create_task(func(self, *args, **kwargs))
|
||||||
done, _ = await asyncio.wait(
|
disconnect_task = asyncio.create_task(disconnected_event.wait())
|
||||||
(task, disconnected_event.wait()),
|
await asyncio.wait(
|
||||||
|
(action_task, disconnect_task),
|
||||||
return_when=asyncio.FIRST_COMPLETED,
|
return_when=asyncio.FIRST_COMPLETED,
|
||||||
)
|
)
|
||||||
if disconnected_event.is_set():
|
if disconnect_task.done():
|
||||||
task.cancel()
|
action_task.cancel()
|
||||||
with contextlib.suppress(asyncio.CancelledError):
|
with contextlib.suppress(asyncio.CancelledError):
|
||||||
await task
|
await action_task
|
||||||
|
|
||||||
raise BleakError(
|
raise BleakError(
|
||||||
f"{self._source_name}: " # pylint: disable=protected-access
|
f"{self._source_name}: " # pylint: disable=protected-access
|
||||||
@ -84,7 +85,7 @@ def verify_connected(func: _WrapFuncType) -> _WrapFuncType:
|
|||||||
f" {self._ble_device.address}: " # pylint: disable=protected-access
|
f" {self._ble_device.address}: " # pylint: disable=protected-access
|
||||||
"Disconnected during operation"
|
"Disconnected during operation"
|
||||||
)
|
)
|
||||||
return next(iter(done)).result()
|
return action_task.result()
|
||||||
|
|
||||||
return cast(_WrapFuncType, _async_wrap_bluetooth_connected_operation)
|
return cast(_WrapFuncType, _async_wrap_bluetooth_connected_operation)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user