diff --git a/adafruit_ble/__init__.py b/adafruit_ble/__init__.py index 8a45b6d..c730ea8 100755 --- a/adafruit_ble/__init__.py +++ b/adafruit_ble/__init__.py @@ -265,7 +265,7 @@ def start_scan( # otherwise. if adv_type not in advertisement_types: continue - advertisement = adv_type.from_entry(entry) + advertisement = adv_type(entry=entry) if advertisement: yield advertisement diff --git a/adafruit_ble/advertising/__init__.py b/adafruit_ble/advertising/__init__.py index 2ed55e1..454bc44 100644 --- a/adafruit_ble/advertising/__init__.py +++ b/adafruit_ble/advertising/__init__.py @@ -236,31 +236,21 @@ class Advertisement: # MAX_LEGACY_DATA_SIZE = 31 # """Data size in a regular BLE packet.""" - def __init__(self): - """Create an advertising packet.""" + def __init__(self, *, entry=None): + """Create an empty advertising packet or one from a ScanEntry.""" self.data_dict = {} self.address = None self._rssi = None self.connectable = False self.mutable = True self.scan_response = False - - @classmethod - def from_entry(cls, entry): - """Create an Advertisement based on the given ScanEntry. This is done automatically by - `BLERadio` for all scan results.""" - self = cls() - # If data_dict is available, use it directly. Otherwise decode the bytestring. - if hasattr(entry, "data_dict"): - self.data_dict = entry.data_dict - else: + if entry: self.data_dict = decode_data(entry.advertisement_bytes) - self.address = entry.address - self._rssi = entry.rssi # pylint: disable=protected-access - self.connectable = entry.connectable - self.scan_response = entry.scan_response - self.mutable = False - return self + self.address = entry.address + self._rssi = entry.rssi # pylint: disable=protected-access + self.connectable = entry.connectable + self.scan_response = entry.scan_response + self.mutable = False @property def rssi(self): diff --git a/adafruit_ble/advertising/apple.py b/adafruit_ble/advertising/apple.py deleted file mode 100644 index 93ee854..0000000 --- a/adafruit_ble/advertising/apple.py +++ /dev/null @@ -1,13 +0,0 @@ -# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -# class iBeacon(Advertisement): -# # Apple manufacturer data with subtype 2 -# match_prefixes = (b"\xff\x00\x4c\x02",) -# -# proximity_uuid = -# major = -# minor = -# signal_power = -# diff --git a/adafruit_ble/advertising/standard.py b/adafruit_ble/advertising/standard.py index 76ba807..edb9fa9 100644 --- a/adafruit_ble/advertising/standard.py +++ b/adafruit_ble/advertising/standard.py @@ -159,8 +159,8 @@ class ProvideServicesAdvertisement(Advertisement): services = ServiceList(standard_services=[0x02, 0x03], vendor_services=[0x06, 0x07]) """List of services the device can provide.""" - def __init__(self, *services): - super().__init__() + def __init__(self, *services, entry=None): + super().__init__(entry=entry) if services: self.services.extend(services) self.connectable = True @@ -184,8 +184,8 @@ class SolicitServicesAdvertisement(Advertisement): solicited_services = ServiceList(standard_services=[0x14], vendor_services=[0x15]) """List of services the device would like to use.""" - def __init__(self, *services): - super().__init__() + def __init__(self, *services, entry=None): + super().__init__(entry=entry) self.solicited_services.extend(services) self.connectable = True self.flags.general_discovery = True diff --git a/docs/advertising.rst b/docs/advertising.rst index 094174d..eff9546 100644 --- a/docs/advertising.rst +++ b/docs/advertising.rst @@ -9,6 +9,3 @@ .. automodule:: adafruit_ble.advertising.adafruit :members: - -.. automodule:: adafruit_ble.advertising.apple - :members: