Skip to content

Commit 3bfef11

Browse files
committed
Get rid of move_to_end
Instead, just set a placeholder sequence_number Fixes adafruit#18
1 parent ac76109 commit 3bfef11

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

adafruit_ble_broadcastnet.py

+3-10
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ class AdafruitSensorMeasurement(Advertisement):
149149
"""Battery voltage in millivolts. Saves two bytes over voltage and is more readable in bare
150150
packets."""
151151

152-
def __init__(self, *, sequence_number=None):
152+
def __init__(self, *, sequence_number=0):
153153
super().__init__()
154-
if sequence_number:
155-
self.sequence_number = sequence_number
154+
# Always set the sequence number so that it's always first in the packet
155+
self.sequence_number = sequence_number
156156

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

167-
def __bytes__(self):
168-
"""The raw packet bytes."""
169-
# Must reorder the ManufacturerData contents so the sequence number field is always first.
170-
# Necessary to ensure that match_prefixes works right to reconstruct on the receiver.
171-
self.data_dict[255].data.move_to_end(3, last=False)
172-
return super().__bytes__()
173-
174167
def split(self, max_packet_size=31):
175168
"""Split the measurement into multiple measurements with the given max_packet_size. Yields
176169
each submeasurement."""

0 commit comments

Comments
 (0)