Skip to content

Get rid of move_to_end #19

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 2 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
16 changes: 5 additions & 11 deletions adafruit_ble_broadcastnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,11 @@ class AdafruitSensorMeasurement(Advertisement):
"""Battery voltage in millivolts. Saves two bytes over voltage and is more readable in bare
packets."""

def __init__(self, *, sequence_number=None):
super().__init__()
if sequence_number:
self.sequence_number = sequence_number
def __init__(self, *, entry=None, sequence_number=0):
super().__init__(entry=entry)
if entry:
return
self.sequence_number = sequence_number

def __str__(self):
parts = []
Expand All @@ -164,13 +165,6 @@ def __str__(self):
parts.append("{}={}".format(attr, str(value)))
return "<{} {} >".format(self.__class__.__name__, " ".join(parts))

def __bytes__(self):
"""The raw packet bytes."""
# Must reorder the ManufacturerData contents so the sequence number field is always first.
# Necessary to ensure that match_prefixes works right to reconstruct on the receiver.
self.data_dict[255].data.move_to_end(3, last=False)
return super().__bytes__()

def split(self, max_packet_size=31):
"""Split the measurement into multiple measurements with the given max_packet_size. Yields
each submeasurement."""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
# Author details
author="Adafruit Industries",
author_email="[email protected]",
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-ble"],
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-ble >= 8.0.0"],
# Choose your license
license="MIT",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
Expand Down