diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 62262e04..20120dce 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -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) ====================== diff --git a/bleak/uuids.py b/bleak/uuids.py index 281975e8..0ea79d44 100644 --- a/bleak/uuids.py +++ b/bleak/uuids.py @@ -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)) diff --git a/tests/test_uuid.py b/tests/test_uuid.py index ab97edda..c306f040 100644 --- a/tests/test_uuid.py +++ b/tests/test_uuid.py @@ -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():