1
- # The MIT License (MIT)
1
+ # SPDX-FileCopyrightText: 2018 Dan Halbert for Adafruit Industries
2
2
#
3
- # Copyright (c) 2018 Dan Halbert for Adafruit Industries
4
- #
5
- # Permission is hereby granted, free of charge, to any person obtaining a copy
6
- # of this software and associated documentation files (the "Software"), to deal
7
- # in the Software without restriction, including without limitation the rights
8
- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- # copies of the Software, and to permit persons to whom the Software is
10
- # furnished to do so, subject to the following conditions:
11
- #
12
- # The above copyright notice and this permission notice shall be included in
13
- # all copies or substantial portions of the Software.
14
- #
15
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- # THE SOFTWARE.
3
+ # SPDX-License-Identifier: MIT
4
+
22
5
"""
23
6
Advertising is the first phase of BLE where devices can broadcast
24
7
"""
@@ -38,7 +21,7 @@ def to_bytes_literal(seq):
38
21
39
22
def decode_data (data , * , key_encoding = "B" ):
40
23
"""Helper which decodes length encoded structures into a dictionary with the given key
41
- encoding."""
24
+ encoding."""
42
25
i = 0
43
26
data_dict = {}
44
27
key_size = struct .calcsize (key_encoding )
@@ -73,7 +56,7 @@ def compute_length(data_dict, *, key_encoding="B"):
73
56
74
57
def encode_data (data_dict , * , key_encoding = "B" ):
75
58
"""Helper which encodes dictionaries into length encoded structures with the given key
76
- encoding."""
59
+ encoding."""
77
60
length = compute_length (data_dict , key_encoding = key_encoding )
78
61
data = bytearray (length )
79
62
key_size = struct .calcsize (key_encoding )
@@ -151,7 +134,7 @@ def __str__(self):
151
134
class String (AdvertisingDataField ):
152
135
"""UTF-8 encoded string in an Advertisement.
153
136
154
- Not null terminated once encoded because length is always transmitted."""
137
+ Not null terminated once encoded because length is always transmitted."""
155
138
156
139
def __init__ (self , * , advertising_data_type ):
157
140
self ._adt = advertising_data_type
@@ -265,7 +248,7 @@ def __init__(self):
265
248
@classmethod
266
249
def from_entry (cls , entry ):
267
250
"""Create an Advertisement based on the given ScanEntry. This is done automatically by
268
- `BLERadio` for all scan results."""
251
+ `BLERadio` for all scan results."""
269
252
self = cls ()
270
253
# If data_dict is available, use it directly. Otherwise decode the bytestring.
271
254
if hasattr (entry , "data_dict" ):
@@ -282,7 +265,7 @@ def from_entry(cls, entry):
282
265
@property
283
266
def rssi (self ):
284
267
"""Signal strength of the scanned advertisement. Only available on Advertisements returned
285
- from `BLERadio.start_scan()`. (read-only)"""
268
+ from `BLERadio.start_scan()`. (read-only)"""
286
269
return self ._rssi
287
270
288
271
@classmethod
0 commit comments