diff --git a/eq3bt/bleakconnection.py b/eq3bt/bleakconnection.py index d0d040d..c588df1 100644 --- a/eq3bt/bleakconnection.py +++ b/eq3bt/bleakconnection.py @@ -31,14 +31,18 @@ def __init__(self, mac, iface): self._mac = mac self._iface = iface self._callbacks = {} - self._notifyevent = asyncio.Event() - self._notification_handle = None try: self._loop = asyncio.get_running_loop() except RuntimeError: self._loop = asyncio.new_event_loop() asyncio.set_event_loop(self._loop) + try: # necessary on python < 3.10 + self._notifyevent = asyncio.Event(loop=self._loop) + except TypeError: # raised on >= 3.10 + self._notifyevent = asyncio.Event() + + self._notification_handle = None def __enter__(self): """ @@ -79,10 +83,10 @@ def __exit__(self, exc_type, exc_val, exc_tb): self._loop.run_until_complete(self._conn.disconnect()) self._conn = None - async def on_notification(self, handle, data): + async def on_notification(self, characteristic, data): """Handle Callback from a Bluetooth (GATT) request.""" # The notification handles are off-by-one compared to gattlib and bluepy - handle = handle + 1 + handle = characteristic.handle + 1 _LOGGER.debug( "Got notification from %s: %s", handle, codecs.encode(data, "hex") )