mirror of
https://github.com/NixOS/nixpkgs.git
synced 2026-06-07 13:53:42 +00:00
29 lines
979 B
Diff
29 lines
979 B
Diff
diff --git a/motionblindsble/device.py b/motionblindsble/device.py
|
|
index 9c6ecf9..0d9affc 100644
|
|
--- a/motionblindsble/device.py
|
|
+++ b/motionblindsble/device.py
|
|
@@ -11,6 +11,8 @@ from asyncio import (
|
|
TimerHandle,
|
|
create_task,
|
|
get_event_loop,
|
|
+ new_event_loop,
|
|
+ set_event_loop,
|
|
sleep,
|
|
wait,
|
|
)
|
|
@@ -248,7 +250,13 @@ class ConnectionQueue:
|
|
)
|
|
return device._create_task(target=device.establish_connection())
|
|
_LOGGER.debug("(%s) Connecting", device.ble_device.address)
|
|
- return get_event_loop().create_task(device.establish_connection())
|
|
+ try:
|
|
+ loop = get_event_loop()
|
|
+ except RuntimeError:
|
|
+ loop = new_event_loop()
|
|
+ set_event_loop(loop)
|
|
+
|
|
+ return loop.create_task(device.establish_connection())
|
|
|
|
async def wait_for_connection(self, device: MotionDevice) -> bool:
|
|
"""Wait for a connection, return True to last caller if connected."""
|