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

32 bit UUID causing exceptions during discovery #1314

Closed
al-little opened this issue May 16, 2023 · 1 comment · Fixed by #1315
Closed

32 bit UUID causing exceptions during discovery #1314

al-little opened this issue May 16, 2023 · 1 comment · Fixed by #1315
Labels
bug Something isn't working

Comments

@al-little
Copy link
Contributor

al-little commented May 16, 2023

  • bleak version: 0.19.5
  • Python version: 3.10
  • Operating System: MacOS
  • BlueZ version (bluetoothctl -v) in case of Linux: N/A

Description

Doing a quick scan on MacOS is raising some unhandled exceptions.

    try:
        self.bleak_devices = await BleakScanner.discover()
    except BleakError as exception:
        logging.error("Quick scan failed: %s", exception)

Similar issue
adafruit/Adafruit_Blinka_bleio#62 (review)

def normalize_uuid_str(uuid: str) -> str:
    """
    Normaizes a UUID to the format used by Bleak.

    - Converted to lower case.
    - 16-bit UUIDs are expanded to 128-bit.

    .. versionadded:: 0.20.0
    """
    if len(uuid) == 4:
        # Bluetooth SIG registered 16-bit UUIDs
        uuid = f"0000{uuid}-0000-1000-8000-00805f9b34fb"

    # let UUID class do the validation and conversion to lower case
    return str(UUID(uuid))

What I Did

Performing a Quick Scan. One of the devices has a service UUID string of “DAF51C01”.

Logs

File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/asyncio/events.py", line 80, in _run
    self._context.run(self._callback, *self._args)
  File "/Users/alittle/code/mobapps-python-app-gaiaclient/.venv/lib/python3.10/site-packages/bleak/backends/corebluetooth/CentralManagerDelegate.py", line 265, in did_discover_peripheral
    callback(peripheral, advertisementData, RSSI)
  File "/Users/alittle/code/mobapps-python-app-gaiaclient/.venv/lib/python3.10/site-packages/bleak/backends/corebluetooth/scanner.py", line 116, in callback
    service_uuids = [
  File "/Users/alittle/code/mobapps-python-app-gaiaclient/.venv/lib/python3.10/site-packages/bleak/backends/corebluetooth/scanner.py", line 117, in <listcomp>
    cb_uuid_to_str(u) for u in a.get("kCBAdvDataServiceUUIDs", [])
  File "/Users/alittle/code/mobapps-python-app-gaiaclient/.venv/lib/python3.10/site-packages/bleak/backends/corebluetooth/utils.py", line 19, in cb_uuid_to_str
    return normalize_uuid_str(uuid.UUIDString())
  File "/Users/alittle/code/mobapps-python-app-gaiaclient/.venv/lib/python3.10/site-packages/bleak/uuids.py", line 1167, in normalize_uuid_str
    return str(UUID(uuid))
  File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/uuid.py", line 177, in __init__
    raise ValueError('badly formed hexadecimal UUID string')
ValueError: badly formed hexadeci
@dlech dlech added the enhancement New feature or request label May 16, 2023
@dlech
Copy link
Collaborator

dlech commented May 16, 2023

Happy to take a pull request to add support for 32-bit UUIDs.

@dlech dlech added bug Something isn't working and removed enhancement New feature or request labels May 16, 2023
@dlech dlech mentioned this issue Sep 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants