Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ repos:
hooks:
- id: black

- repo: https://gitlab.com/pycqa/flake8
- repo: https://github.com/pycqa/flake8
rev: 3.9.2
hooks:
- id: flake8
Expand Down
13 changes: 10 additions & 3 deletions eq3bt/bleakconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +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()
_LOGGER.debug("Using existing asyncio loop")
except RuntimeError:
self._loop = asyncio.new_event_loop()
_LOGGER.debug("Creating new asyncio loop")
asyncio.set_event_loop(self._loop)

self._notifyevent = asyncio.Event()

def __enter__(self):
"""
Context manager __enter__ for connecting the device
Expand Down Expand Up @@ -79,10 +82,14 @@ 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
try:
handle = characteristic.handle + 1
except: # noqa: E722 # fallback to old-style, int-based handle
handle = characteristic + 1

_LOGGER.debug(
"Got notification from %s: %s", handle, codecs.encode(data, "hex")
)
Expand Down