Skip to content

Commit aee83fb

Browse files
authored
Merge pull request adafruit#97 from kevinjwalters/dictorderchange
ManufacturerData tweak to offer control over ordering of its data fields
2 parents 41f7a35 + fb12b95 commit aee83fb

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

adafruit_ble/advertising/standard.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"""
3030

3131
import struct
32+
from collections import OrderedDict
3233

3334
from . import (
3435
Advertisement,
@@ -211,7 +212,9 @@ def __init__(self, *services):
211212
class ManufacturerData(AdvertisingDataField):
212213
"""Encapsulates manufacturer specific keyed data bytes. The manufacturer is identified by the
213214
company_id and the data is structured like an advertisement with a configurable key
214-
format."""
215+
format. The order of the serialized data is determined by the order that the
216+
`ManufacturerDataField` attributes are set in - this can be useful for
217+
`match_prefixes` in an `Advertisement` sub-class."""
215218

216219
def __init__(
217220
self, obj, *, advertising_data_type=0xFF, company_id, key_encoding="B"
@@ -220,7 +223,7 @@ def __init__(
220223
self._company_id = company_id
221224
self._adt = advertising_data_type
222225

223-
self.data = {}
226+
self.data = OrderedDict() # makes field order match order they are set in
224227
self.company_id = company_id
225228
encoded_company = struct.pack("<H", company_id)
226229
if 0xFF in obj.data_dict:

0 commit comments

Comments
 (0)