Skip to content

Commit 214e277

Browse files
committed
Black and lint
1 parent 80ce526 commit 214e277

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

adafruit_ble_broadcastnet.py

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,40 +27,27 @@
2727
2828
2929
* Author(s): Scott Shawcroft
30-
31-
Implementation Notes
32-
--------------------
33-
34-
**Hardware:**
35-
36-
.. todo:: Add links to any specific hardware product page(s), or category page(s). Use unordered list & hyperlink rST
37-
inline format: "* `Link Text <url>`_"
38-
39-
**Software and Dependencies:**
40-
41-
* Adafruit CircuitPython firmware for the supported boards:
42-
https://github.com/adafruit/circuitpython/releases
43-
* Adafruit's BLE library: https://github.com/adafruit/Adafruit_CircuitPython_BLE
4430
"""
4531

32+
import struct
33+
import time
4634
import adafruit_ble
4735
from adafruit_ble.advertising import Advertisement, LazyObjectField
4836
from adafruit_ble.advertising.standard import ManufacturerData, ManufacturerDataField
4937
from micropython import const
50-
import struct
51-
import time
5238

5339
__version__ = "0.0.0-auto.0"
5440
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE_BroadcastNet.git"
5541

56-
_ble = adafruit_ble.BLERadio()
57-
_sequence_number = 0
42+
_ble = adafruit_ble.BLERadio() # pylint: disable=invalid-name
43+
_sequence_number = 0 # pylint: disable=invalid-name
5844

5945

6046
def broadcast(measurement, *, broadcast_time=0.1, extended=False):
6147
"""Broadcasts the given measurement for the given broadcast time. If extended is False and the
62-
measurement would be too long, it will be split into multiple measurements for transmission."""
63-
global _sequence_number
48+
measurement would be too long, it will be split into multiple measurements for transmission.
49+
"""
50+
global _sequence_number # pylint: disable=global-statement,invalid-name
6451
for submeasurement in measurement.split(252 if extended else 31):
6552
submeasurement.sequence_number = _sequence_number
6653
_ble.start_advertising(submeasurement, scan_response=None)
@@ -69,9 +56,12 @@ def broadcast(measurement, *, broadcast_time=0.1, extended=False):
6956
_sequence_number = (_sequence_number + 1) % 256
7057

7158

72-
device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format(
73-
*_ble._adapter.address.address_bytes
59+
device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format( # pylint: disable=invalid-name
60+
*reversed(
61+
list(_ble._adapter.address.address_bytes)
62+
) # pylint: disable=protected-access
7463
)
64+
"""Device address as a string."""
7565

7666
_MANUFACTURING_DATA_ADT = const(0xFF)
7767
_ADAFRUIT_COMPANY_ID = const(0x0822)
@@ -140,10 +130,10 @@ class AdafruitSensorMeasurement(Advertisement):
140130
"""Color as RGB integer."""
141131

142132
# alarm = ManufacturerDataField(0x0a0f, "<f")
143-
"""Alarm as a start date and time and recurrence period. Not supported."""
133+
# """Alarm as a start date and time and recurrence period. Not supported."""
144134

145135
# datetime = ManufacturerDataField(0x0a10, "<f")
146-
"""Date and time as a struct. Not supported."""
136+
# """Date and time as a struct. Not supported."""
147137

148138
duty_cycle = ManufacturerDataField(0x0A11, "<f")
149139
"""16-bit PWM duty cycle. Independent of frequency."""
@@ -177,6 +167,8 @@ def __str__(self):
177167
return "<{} {} >".format(self.__class__.__name__, " ".join(parts))
178168

179169
def split(self, max_packet_size=31):
170+
"""Split the measurement into multiple measurements with the given max_packet_size. Yields
171+
each submeasurement."""
180172
current_size = 8 # baseline for mfg data and sequence number
181173
if current_size + len(self.manufacturer_data) < max_packet_size:
182174
yield self

examples/ble_broadcastnet_wifi_bridge.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,7 @@ def convert_to_feed_data(values, attribute_name, attribute_instance):
102102

103103

104104
ble = adafruit_ble.BLERadio()
105-
address = ble._adapter.address
106-
bridge_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format(*address.address_bytes)
107-
print("This is BroadcastNet bridge:", bridge_address)
105+
print("This is BroadcastNet bridge:", adafruit_ble_broadcastnet.device_address)
108106
print()
109107

110108
print("Fetching existing feeds.")

0 commit comments

Comments
 (0)