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

Error in example in https://bleak.readthedocs.io/en/latest/troubleshooting.html #1334

Closed
jsmif opened this issue Jun 14, 2023 · 3 comments
Closed

Comments

@jsmif
Copy link

jsmif commented Jun 14, 2023

  • bleak version: bleak-0.21.0a1
  • Python version: Python 3.10.6
  • Operating System: Ubuntu 22.04
  • BlueZ version (bluetoothctl -v) in case of Linux: 5.64

Description

Just pointing out an error in the documentation

What I Did

Copied the following code from https://bleak.readthedocs.io/en/latest/troubleshooting.html into test.py

import asyncio
from typing import Sequence

from bleak import BleakClient, BleakScanner
from bleak.backends.device import BLEDevice


async def find_all_devices_services()
    scanner = BleakScanner()
    devices: Sequence[BLEDevice] = scanner.discover(timeout=5.0)
    for d in devices:
        async with BleakClient(d) as client:
            print(client.services)


asyncio.run(find_all_devices_services())

The first error was

 python3 test.py 
  File "/home/user/Downloads/bleak/examples/test.py", line 8
    async def find_all_devices_services()
                                         ^
SyntaxError: expected ':'

Once corrected by adding a :, I got the error:

 python3 test.py 
Traceback (most recent call last):
  File "/home/user/Downloads/bleak/examples/test.py", line 16, in <module>
    asyncio.run(find_all_devices_services())
  File "/usr/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.10/asyncio/base_events.py", line 646, in run_until_complete
    return future.result()
  File "/home/user/Downloads/bleak/examples/test.py", line 11, in find_all_devices_services
    for d in devices:
TypeError: 'coroutine' object is not iterable
sys:1: RuntimeWarning: coroutine 'BleakScanner.discover' was never awaited
@dlech dlech closed this as completed in 0b04eec Jun 14, 2023
dlech added a commit that referenced this issue Jun 14, 2023
dlech added a commit that referenced this issue Jun 14, 2023
Also fix missing `:` and don't create unnecessary instance of BleakScanner.

Fixes: #1334
@dlech
Copy link
Collaborator

dlech commented Jun 14, 2023

Thanks for the report. This should be fixed now.

@pymenow
Copy link

pymenow commented Jun 20, 2023

@dlech do you have an estimate on when the next bleak release will happen ? My package depends on fixes that are in the develop branch .

@dlech
Copy link
Collaborator

dlech commented Jun 20, 2023

No ETA, but I've been trying to do quarterly releases, so we are due for one soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants