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

Using adapter other than 'hci0' gives error during discovery #76

Closed
yggdr opened this issue Jun 19, 2019 · 2 comments
Closed

Using adapter other than 'hci0' gives error during discovery #76

yggdr opened this issue Jun 19, 2019 · 2 comments
Assignees
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend bug Something isn't working

Comments

@yggdr
Copy link

yggdr commented Jun 19, 2019

  • bleak version:
    0.4.2 + workaround patch from Unhandled error in discovery.py #69 (+ a few prints for debugging, so line numbers might be off by 1 or 2)
  • Python version:
    3.7.3
  • Operating System:
    Ubuntu 19.04 / Linux 5.0.0-16-generic #17

Description

Using an adapter other than 'hci0' does get set in the BleakClientBlueZDBus instance, but not propagated to all called functions, like e.g. backends.bluezdbus.discovery.discover

What I Did

Create an instance with a non-default device and have it try to connect. Very stripped down version of our code:

from bleak import BleakClient
import sys
import asyncio

class MyInternalStuff:
    def __init__(self, ble_addr, *, adapter="hci0", loop):
        self._adapter = adapter
        self._dev = BleakClient(ble_addr, device=self._adapter, timeout=35)
    async def __aenter__(self):
        await self._dev.__aenter__()
    async def __aexit__(self, exc_type, exc_val, exc_tb):
        await self._dev.__aexit__(exc_type, exc_val, exc_tb)

async def main(loop):
    async with MyInternalStuff(ble_addr="12:34:56:78:90:ab", adapter='hci1', loop=loop):
        pass

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    sys.exit(loop.run_until_complete(main(loop)))

gives

Traceback (most recent call last):
  File "bug.py", line 25, in <module>
    sys.exit(loop.run_until_complete(main(loop)))
  File "/usr/lib/python3.7/asyncio/base_events.py", line 584, in run_until_complete
    return future.result()
  File "bug.py", line 19, in main
    async with MyInternalStuff(ble_addr="12:34:56:78:90:ab", adapter='hci1', loop=loop):
  File "bug.py", line 12, in __aenter__
    await self._dev.__aenter__()
  File "/home/yggdrasil/.virtualenvs/svhsystemtests/lib/python3.7/site-packages/bleak/backends/client.py", line 41, in __aenter__
    await self.connect()
  File "/home/yggdrasil/.virtualenvs/svhsystemtests/lib/python3.7/site-packages/bleak/backends/bluezdbus/client.py", line 65, in connect
    await discover(timeout=0.1, loop=self.loop)
  File "/home/yggdrasil/.virtualenvs/svhsystemtests/lib/python3.7/site-packages/bleak/backends/bluezdbus/discovery.py", line 143, in discover
    adapter_path, interface = _filter_on_adapter(objects, device)
  File "/home/yggdrasil/.virtualenvs/svhsystemtests/lib/python3.7/site-packages/bleak/backends/bluezdbus/discovery.py", line 26, in _filter_on_adapter
    raise Exception("Bluetooth adapter not found")
Exception: Bluetooth adapter not found

Patching backends/bluezdbus/client.py:65 like so:
await discover(timeout=0.1, device=self.device, loop=self.loop)
fixes this particular instance, but there might be more places this is missing.

@hbldh hbldh self-assigned this Jun 24, 2019
@hbldh hbldh added the bug Something isn't working label Jun 24, 2019
@hbldh
Copy link
Owner

hbldh commented Jun 24, 2019

This is definitely a an oversight, and I will remedy this bug in version 0.4.3, which will be released shortly.

hbldh added a commit that referenced this issue Jun 24, 2019
Needs more testing.
@hbldh hbldh added the Backend: BlueZ Issues and PRs relating to the BlueZ backend label Jun 24, 2019
@hbldh hbldh closed this as completed in 9aebbb2 Jun 30, 2019
@hbldh
Copy link
Owner

hbldh commented Jul 1, 2019

Made necessary modifications, tested it with a second adapter in Ubuntu 18.04 and released 0.4.3.
Thank you for reporting this and reopen if you find further problems with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Backend: BlueZ Issues and PRs relating to the BlueZ backend bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants