From ce9472bf42cecf86818469bb3a59cd4975d5b21f Mon Sep 17 00:00:00 2001 From: Abel Lucas Date: Mon, 31 Oct 2022 20:49:41 +0000 Subject: [PATCH] core: change `AdvertisingData.get` default `raw` behavior to False --- apps/console.py | 4 ++-- bumble/core.py | 2 +- bumble/device.py | 4 ++-- tests/core_test.py | 16 ++++++++-------- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/apps/console.py b/apps/console.py index 744d7da9..489fdfd6 100644 --- a/apps/console.py +++ b/apps/console.py @@ -877,9 +877,9 @@ class ScanResult: else: type_color = colors.cyan - name = self.ad_data.get(AdvertisingData.COMPLETE_LOCAL_NAME) + name = self.ad_data.get(AdvertisingData.COMPLETE_LOCAL_NAME, raw=True) if name is None: - name = self.ad_data.get(AdvertisingData.SHORTENED_LOCAL_NAME) + name = self.ad_data.get(AdvertisingData.SHORTENED_LOCAL_NAME, raw=True) if name: # Convert to string try: diff --git a/bumble/core.py b/bumble/core.py index a74a17aa..302ee6a3 100644 --- a/bumble/core.py +++ b/bumble/core.py @@ -827,7 +827,7 @@ class AdvertisingData: self.ad_structures.append((ad_type, ad_data)) offset += length - def get(self, type_id, return_all=False, raw=True): + def get(self, type_id, return_all=False, raw=False): ''' Get Advertising Data Structure(s) with a given type diff --git a/bumble/device.py b/bumble/device.py index dc48fc22..3e83153f 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -1402,9 +1402,9 @@ class Device(CompositeEventEmitter): # Scan/inquire with event handlers to handle scan/inquiry results def on_peer_found(address, ad_data): - local_name = ad_data.get(AdvertisingData.COMPLETE_LOCAL_NAME) + local_name = ad_data.get(AdvertisingData.COMPLETE_LOCAL_NAME, raw=True) if local_name is None: - local_name = ad_data.get(AdvertisingData.SHORTENED_LOCAL_NAME) + local_name = ad_data.get(AdvertisingData.SHORTENED_LOCAL_NAME, raw=True) if local_name is not None: if local_name.decode('utf-8') == name: peer_address.set_result(address) diff --git a/tests/core_test.py b/tests/core_test.py index f4bdd838..fa397db6 100644 --- a/tests/core_test.py +++ b/tests/core_test.py @@ -24,19 +24,19 @@ def test_ad_data(): ad = AdvertisingData.from_bytes(data) ad_bytes = bytes(ad) assert(data == ad_bytes) - assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME) is None) - assert(ad.get(AdvertisingData.TX_POWER_LEVEL) == bytes([123])) - assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True) == []) - assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True) == [bytes([123])]) + assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, raw=True) is None) + assert(ad.get(AdvertisingData.TX_POWER_LEVEL, raw=True) == bytes([123])) + assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True, raw=True) == []) + assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True, raw=True) == [bytes([123])]) data2 = bytes([2, AdvertisingData.TX_POWER_LEVEL, 234]) ad.append(data2) ad_bytes = bytes(ad) assert(ad_bytes == data + data2) - assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME) is None) - assert(ad.get(AdvertisingData.TX_POWER_LEVEL) == bytes([123])) - assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True) == []) - assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True) == [bytes([123]), bytes([234])]) + assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, raw=True) is None) + assert(ad.get(AdvertisingData.TX_POWER_LEVEL, raw=True) == bytes([123])) + assert(ad.get(AdvertisingData.COMPLETE_LOCAL_NAME, return_all=True, raw=True) == []) + assert(ad.get(AdvertisingData.TX_POWER_LEVEL, return_all=True, raw=True) == [bytes([123]), bytes([234])]) # -----------------------------------------------------------------------------