From ab4859bd948738b8ee243fab457bfa06919419c7 Mon Sep 17 00:00:00 2001 From: Abel Lucas Date: Tue, 29 Nov 2022 16:26:02 +0000 Subject: [PATCH 1/3] device: fix typos --- bumble/device.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bumble/device.py b/bumble/device.py index fde4ab4..6feef9a 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -1911,7 +1911,7 @@ class Device(CompositeEventEmitter): self.connections[connection_handle] = connection # We may have an accept ongoing waiting for a connection request for `peer_address`. - # Typicaly happen when using `connect` to the same `peer_address` we are waiting with + # Typically happen when using `connect` to the same `peer_address` we are waiting with # an `accept` for. # In this case, set the completed `connection` to the `accept` future result. if peer_address in self.classic_pending_accepts: @@ -2094,7 +2094,7 @@ class Device(CompositeEventEmitter): def on_ssp_complete(self, connection): # On Secure Simple Pairing complete, in case: # - Connection isn't already authenticated - # - AND We are not the initiator of the authentication + # - AND we are not the initiator of the authentication # We must trigger authentication to known if we are truly authenticated if not connection.authenticating and not connection.authenticated: logger.debug(f'*** Trigger Connection Authentication: [0x{connection.handle:04X}] {connection.peer_address}') From 99a0eb21c10c02de76fb34cb0367384931d5210a Mon Sep 17 00:00:00 2001 From: Abel Lucas Date: Tue, 29 Nov 2022 16:32:12 +0000 Subject: [PATCH 2/3] address: fix deprecated use of combined `@classmethod` and `@property` --- bumble/hci.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/bumble/hci.py b/bumble/hci.py index be5973b..4805a6b 100644 --- a/bumble/hci.py +++ b/bumble/hci.py @@ -1652,16 +1652,6 @@ class Address: ADDRESS_TYPE_SPEC = {'size': 1, 'mapper': lambda x: Address.address_type_name(x)} - @classmethod - @property - def ANY(cls): - return cls(b"\xff\xff\xff\xff\xff\xff", cls.PUBLIC_DEVICE_ADDRESS) - - @classmethod - @property - def NIL(cls): - return cls(b"\x00\x00\x00\x00\x00\x00", cls.PUBLIC_DEVICE_ADDRESS) - @staticmethod def address_type_name(address_type): return name_or_number(Address.ADDRESS_TYPE_NAMES, address_type) @@ -1759,6 +1749,10 @@ class Address: return str + '/P' +# Predefined address values +Address.NIL = Address(b"\xff\xff\xff\xff\xff\xff", Address.PUBLIC_DEVICE_ADDRESS) +Address.ANY = Address(b"\x00\x00\x00\x00\x00\x00", Address.PUBLIC_DEVICE_ADDRESS) + # ----------------------------------------------------------------------------- class OwnAddressType: PUBLIC = 0 From 691450c7de69d9e714897f153455469f99837557 Mon Sep 17 00:00:00 2001 From: Abel Lucas Date: Tue, 29 Nov 2022 16:43:47 +0000 Subject: [PATCH 3/3] gatt: fix `CharacteristicDeclaration.__str__` and associated test --- bumble/gatt.py | 3 ++- tests/gatt_test.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bumble/gatt.py b/bumble/gatt.py index f59e7be..3ba7e23 100644 --- a/bumble/gatt.py +++ b/bumble/gatt.py @@ -295,10 +295,11 @@ class CharacteristicDeclaration(Attribute): value_handle ) + characteristic.uuid.to_pdu_bytes() super().__init__(GATT_CHARACTERISTIC_ATTRIBUTE_TYPE, Attribute.READABLE, declaration_bytes) + self.value_handle = value_handle self.characteristic = characteristic def __str__(self): - return f'CharacteristicDeclaration(handle=0x{self.handle:04X}, value_handle=0x{self.value_handle:04X}, uuid={self.uuid}, properties={Characteristic.properties_as_string(self.properties)})' + return f'CharacteristicDeclaration(handle=0x{self.handle:04X}, value_handle=0x{self.value_handle:04X}, uuid={self.characteristic.uuid}, properties={Characteristic.properties_as_string(self.characteristic.properties)})' # ----------------------------------------------------------------------------- class CharacteristicValue: diff --git a/tests/gatt_test.py b/tests/gatt_test.py index b5bfdbc..9630fde 100644 --- a/tests/gatt_test.py +++ b/tests/gatt_test.py @@ -777,12 +777,12 @@ async def test_server_string(): server.add_service(service) assert str(server.gatt_server) == """Service(handle=0x0001, end=0x0005, uuid=UUID-16:1800 (Generic Access)) -Attribute(handle=0x0002, type=UUID-16:2803 (Characteristic), permissions=1, value=020300002a) +CharacteristicDeclaration(handle=0x0002, value_handle=0x0003, uuid=UUID-16:2A00 (Device Name), properties=READ) Characteristic(handle=0x0003, end=0x0003, uuid=UUID-16:2A00 (Device Name), properties=READ) -Attribute(handle=0x0004, type=UUID-16:2803 (Characteristic), permissions=1, value=020500012a) +CharacteristicDeclaration(handle=0x0004, value_handle=0x0005, uuid=UUID-16:2A01 (Appearance), properties=READ) Characteristic(handle=0x0005, end=0x0005, uuid=UUID-16:2A01 (Appearance), properties=READ) Service(handle=0x0006, end=0x0009, uuid=3A657F47-D34F-46B3-B1EC-698E29B6B829) -Attribute(handle=0x0007, type=UUID-16:2803 (Characteristic), permissions=1, value=1a0800060875ac2563dbb3e3496c03db59b1fd) +CharacteristicDeclaration(handle=0x0007, value_handle=0x0008, uuid=FDB159DB-036C-49E3-B3DB-6325AC750806, properties=READ,WRITE,NOTIFY) Characteristic(handle=0x0008, end=0x0009, uuid=FDB159DB-036C-49E3-B3DB-6325AC750806, properties=READ,WRITE,NOTIFY) Descriptor(handle=0x0009, type=UUID-16:2902 (Client Characteristic Configuration), value=0000)"""