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 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
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Changed
Fixed
-----
- Fix handling all access denied errors when enumerating characteristics on Windows. Fixes #1291.
- Added support for 32bit UUIDs. Fixes #1314

`0.20.2`_ (2023-04-19)
======================
Expand Down
8 changes: 7 additions & 1 deletion bleak/uuids.py
Original file line number Diff line number Diff line change
Expand Up @@ -1155,13 +1155,19 @@ 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.

.. 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.
"""
# See: BLUETOOTH CORE SPECIFICATION Version 5.4 | Vol 3, Part B - Section 2.5.1
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