Skip to content

Handle entry properly for subclasses of Advertisement #125

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 1 commit into from
Apr 19, 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
13 changes: 7 additions & 6 deletions adafruit_ble/advertising/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,19 +238,20 @@ class Advertisement:

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
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
else:
self.data_dict = {}
self.address = None
self._rssi = None
self.connectable = False
self.mutable = True
self.scan_response = False

@property
def rssi(self):
Expand Down
10 changes: 10 additions & 0 deletions adafruit_ble/advertising/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ class ProvideServicesAdvertisement(Advertisement):

def __init__(self, *services, entry=None):
super().__init__(entry=entry)
if entry:
if services:
raise ValueError("Supply services or entry, not both")
# Attributes are supplied by entry.
return
if services:
self.services.extend(services)
self.connectable = True
Expand All @@ -186,6 +191,11 @@ class SolicitServicesAdvertisement(Advertisement):

def __init__(self, *services, entry=None):
super().__init__(entry=entry)
if entry:
if services:
raise ValueError("Supply services or entry, not both")
# Attributes are supplied by entry.
return
self.solicited_services.extend(services)
self.connectable = True
self.flags.general_discovery = True
Expand Down