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

Added support for 32bit UUID's added in 4.1 of the Bluetooth spec #1315

Merged
merged 6 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
9 changes: 8 additions & 1 deletion bleak/uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,13 +1155,20 @@ 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.
- 16-bit and 32-bit UUIDs are expanded to 128-bit.

BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 3, Part B - Section 2.5.1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure we need this in the documentation. I don't expect anyone to actually look it up.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think the Bluetooth spec reference would be better as a code comment rather than a documentation comment.


.. versionadded:: 0.20.0
al-little marked this conversation as resolved.
Show resolved Hide resolved
.. versionchanged:: 0.21.0
Added support for 32-bit UUIDs.
"""
if len(uuid) == 4:
# Bluetooth SIG registered 16-bit UUIDs
uuid = f"0000{uuid}-0000-1000-8000-00805f9b34fb"
elif len(uuid) == 8:
# Bluetooth SIG registered 32-bit UUIDs
uuid = f"{uuid}-0000-1000-8000-00805f9b34fb"

# let UUID class do the validation and conversion to lower case
return str(UUID(uuid))
1 change: 1 addition & 0 deletions tests/test_uuid.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

def test_uuid_length_normalization():
assert normalize_uuid_str("1801") == "00001801-0000-1000-8000-00805f9b34fb"
assert normalize_uuid_str("DAF51C01") == "daf51c01-0000-1000-8000-00805f9b34fb"


def test_uuid_case_normalization():
Expand Down