Skip to content

Commit

Permalink
Added support for 32bit UUID's added in 4.1 of the Bluetooth spec (#1315
Browse files Browse the repository at this point in the history
)
  • Loading branch information
al-little authored Jun 13, 2023
1 parent e3a23ab commit 294e731
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
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
.. 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

0 comments on commit 294e731

Please sign in to comment.