From 964dde139bc3743e1176b178bed27c7e58e1bc5c Mon Sep 17 00:00:00 2001 From: mtttz Date: Sat, 10 Apr 2021 05:00:48 +0200 Subject: [PATCH] add reset_on_start parameter to connect function and pass it through to pygatt --- trionesControl/trionesControl.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/trionesControl/trionesControl.py b/trionesControl/trionesControl.py index 8a91bd2..b3d435d 100644 --- a/trionesControl/trionesControl.py +++ b/trionesControl/trionesControl.py @@ -5,10 +5,23 @@ MAIN_CHARACTERISTIC_UUID = "0000ffd9-0000-1000-8000-00805f9b34fb" log = logging.getLogger(__name__) -def connect(MAC): + +def connect(MAC, reset_on_start=True): + """ + Create and start a new backend adapter and connect it to a device. + + When connecting to multiple devices at the same time make sure to set reset_on_start + to False after the first connection is made, otherwise all connections made before are + invalidated. + + :param string MAC: MAC address of the device to connect to. + :param bool reset_on_start: Perhaps due to a bug in gatttol or pygatt, + but if the bluez backend isn't restarted, it can sometimes lock up + the computer when trying to make a connection to HCI device. + """ try: adapter = pygatt.GATTToolBackend() - adapter.start() + adapter.start(reset_on_start=reset_on_start) device = adapter.connect(MAC) except pygatt.exceptions.NotConnectedError: raise pygatt.exceptions.NotConnectedError("Device nor connected!")