Skip to content

Commit

Permalink
Merge pull request #123 from tannewt/remove_from_entry
Browse files Browse the repository at this point in the history
Remove from_entry and provide entry in __init__
  • Loading branch information
tannewt authored Apr 1, 2021
2 parents 0c7a971 + eae4d47 commit 2f79150
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 39 deletions.
2 changes: 1 addition & 1 deletion adafruit_ble/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 8 additions & 18 deletions adafruit_ble/advertising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
13 changes: 0 additions & 13 deletions adafruit_ble/advertising/apple.py

This file was deleted.

8 changes: 4 additions & 4 deletions adafruit_ble/advertising/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions docs/advertising.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,3 @@

.. automodule:: adafruit_ble.advertising.adafruit
:members:

.. automodule:: adafruit_ble.advertising.apple
:members:

0 comments on commit 2f79150

Please sign in to comment.