Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing two runtime issues on current version from pip #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions eq3bt/bleakconnection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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")
)
Expand Down