Skip to content

Remove from_entry and provide entry in __init__ #123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: