Skip to content

Commit 80ce526

Browse files
committed
Blacken everything
1 parent cd702d2 commit 80ce526

9 files changed

+200
-126
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ jobs:
3939
source actions-ci/install.sh
4040
- name: Library version
4141
run: git describe --dirty --always --tags
42+
- name: Check formatting
43+
run: |
44+
black --check --target-version=py35 .
4245
- name: PyLint
4346
run: |
4447
pylint $( find . -path './adafruit*.py' )

adafruit_ble_broadcastnet.py

Lines changed: 38 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555

5656
_ble = adafruit_ble.BLERadio()
5757
_sequence_number = 0
58+
59+
5860
def broadcast(measurement, *, broadcast_time=0.1, extended=False):
5961
"""Broadcasts the given measurement for the given broadcast time. If extended is False and the
6062
measurement would be too long, it will be split into multiple measurements for transmission."""
@@ -66,71 +68,75 @@ def broadcast(measurement, *, broadcast_time=0.1, extended=False):
6668
_ble.stop_advertising()
6769
_sequence_number = (_sequence_number + 1) % 256
6870

69-
device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format(*_ble._adapter.address.address_bytes)
7071

71-
_MANUFACTURING_DATA_ADT = const(0xff)
72+
device_address = "{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}".format(
73+
*_ble._adapter.address.address_bytes
74+
)
75+
76+
_MANUFACTURING_DATA_ADT = const(0xFF)
7277
_ADAFRUIT_COMPANY_ID = const(0x0822)
7378

79+
7480
class AdafruitSensorMeasurement(Advertisement):
7581
"""Broadcast a single RGB color."""
82+
7683
# This prefix matches all
77-
prefix = struct.pack("<BBH",
78-
3,
79-
_MANUFACTURING_DATA_ADT,
80-
_ADAFRUIT_COMPANY_ID)
84+
prefix = struct.pack("<BBH", 3, _MANUFACTURING_DATA_ADT, _ADAFRUIT_COMPANY_ID)
8185

82-
manufacturer_data = LazyObjectField(ManufacturerData,
83-
"manufacturer_data",
84-
advertising_data_type=_MANUFACTURING_DATA_ADT,
85-
company_id=_ADAFRUIT_COMPANY_ID,
86-
key_encoding="<H")
86+
manufacturer_data = LazyObjectField(
87+
ManufacturerData,
88+
"manufacturer_data",
89+
advertising_data_type=_MANUFACTURING_DATA_ADT,
90+
company_id=_ADAFRUIT_COMPANY_ID,
91+
key_encoding="<H",
92+
)
8793

8894
sequence_number = ManufacturerDataField(0x0003, "<B")
8995
"""Sequence number of the measurement. Used to detect missed packets."""
9096

91-
acceleration = ManufacturerDataField(0x0a00, "<fff", ("x", "y", "z"))
97+
acceleration = ManufacturerDataField(0x0A00, "<fff", ("x", "y", "z"))
9298
"""Acceleration as (x, y, z) tuple of floats in meters per second per second."""
9399

94-
magnetic = ManufacturerDataField(0x0a01, "<fff", ("x", "y", "z"))
100+
magnetic = ManufacturerDataField(0x0A01, "<fff", ("x", "y", "z"))
95101
"""Magnetism as (x, y, z) tuple of floats in micro-Tesla."""
96102

97-
orientation = ManufacturerDataField(0x0a02, "<fff", ("x", "y", "z"))
103+
orientation = ManufacturerDataField(0x0A02, "<fff", ("x", "y", "z"))
98104
"""Absolution orientation as (x, y, z) tuple of floats in degrees."""
99105

100-
gyro = ManufacturerDataField(0x0a03, "<fff", ("x", "y", "z"))
106+
gyro = ManufacturerDataField(0x0A03, "<fff", ("x", "y", "z"))
101107
"""Gyro motion as (x, y, z) tuple of floats in radians per second."""
102108

103-
temperature = ManufacturerDataField(0x0a04, "<f")
109+
temperature = ManufacturerDataField(0x0A04, "<f")
104110
"""Temperature as a float in degrees centigrade."""
105111

106-
eCO2 = ManufacturerDataField(0x0a05, "<f")
112+
eCO2 = ManufacturerDataField(0x0A05, "<f")
107113
"""Equivalent CO2 as a float in parts per million."""
108114

109-
TVOC = ManufacturerDataField(0x0a06, "<f")
115+
TVOC = ManufacturerDataField(0x0A06, "<f")
110116
"""Total Volatile Organic Compounds as a float in parts per billion."""
111117

112-
distance = ManufacturerDataField(0x0a07, "<f")
118+
distance = ManufacturerDataField(0x0A07, "<f")
113119
"""Distance as a float in centimeters."""
114120

115-
light = ManufacturerDataField(0x0a08, "<f")
121+
light = ManufacturerDataField(0x0A08, "<f")
116122
"""Brightness as a float without units."""
117123

118-
lux = ManufacturerDataField(0x0a09, "<f")
124+
lux = ManufacturerDataField(0x0A09, "<f")
119125
"""Brightness as a float in SI lux."""
120126

121-
pressure = ManufacturerDataField(0x0a0a, "<f")
127+
pressure = ManufacturerDataField(0x0A0A, "<f")
122128
"""Pressure as a float in hectopascals."""
123129

124-
relative_humidity = ManufacturerDataField(0x0a0b, "<f")
130+
relative_humidity = ManufacturerDataField(0x0A0B, "<f")
125131
"""Relative humidity as a float percentage."""
126132

127-
current = ManufacturerDataField(0x0a0c, "<f")
133+
current = ManufacturerDataField(0x0A0C, "<f")
128134
"""Current as a float in milliamps."""
129135

130-
voltage = ManufacturerDataField(0x0a0d, "<f")
136+
voltage = ManufacturerDataField(0x0A0D, "<f")
131137
"""Voltage as a float in Volts."""
132138

133-
color = ManufacturerDataField(0x0a0e, "<f")
139+
color = ManufacturerDataField(0x0A0E, "<f")
134140
"""Color as RGB integer."""
135141

136142
# alarm = ManufacturerDataField(0x0a0f, "<f")
@@ -139,19 +145,19 @@ class AdafruitSensorMeasurement(Advertisement):
139145
# datetime = ManufacturerDataField(0x0a10, "<f")
140146
"""Date and time as a struct. Not supported."""
141147

142-
duty_cycle = ManufacturerDataField(0x0a11, "<f")
148+
duty_cycle = ManufacturerDataField(0x0A11, "<f")
143149
"""16-bit PWM duty cycle. Independent of frequency."""
144150

145-
frequency = ManufacturerDataField(0x0a12, "<f")
151+
frequency = ManufacturerDataField(0x0A12, "<f")
146152
"""As integer Hertz"""
147153

148-
value = ManufacturerDataField(0x0a13, "<f")
154+
value = ManufacturerDataField(0x0A13, "<f")
149155
"""16-bit unit-less value. Used for analog values and for booleans."""
150156

151-
weight = ManufacturerDataField(0x0a14, "<f")
157+
weight = ManufacturerDataField(0x0A14, "<f")
152158
"""Weight as a float in grams."""
153159

154-
battery_voltage = ManufacturerDataField(0x0a15, "<H")
160+
battery_voltage = ManufacturerDataField(0x0A15, "<H")
155161
"""Battery voltage in millivolts. Saves two bytes over voltage and is more readable in bare
156162
packets."""
157163

@@ -171,7 +177,7 @@ def __str__(self):
171177
return "<{} {} >".format(self.__class__.__name__, " ".join(parts))
172178

173179
def split(self, max_packet_size=31):
174-
current_size = 8 # baseline for mfg data and sequence number
180+
current_size = 8 # baseline for mfg data and sequence number
175181
if current_size + len(self.manufacturer_data) < max_packet_size:
176182
yield self
177183
return

docs/conf.py

Lines changed: 65 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,19 @@
22

33
import os
44
import sys
5-
sys.path.insert(0, os.path.abspath('..'))
5+
6+
sys.path.insert(0, os.path.abspath(".."))
67

78
# -- General configuration ------------------------------------------------
89

910
# Add any Sphinx extension module names here, as strings. They can be
1011
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
1112
# ones.
1213
extensions = [
13-
'sphinx.ext.autodoc',
14-
'sphinx.ext.intersphinx',
15-
'sphinx.ext.napoleon',
16-
'sphinx.ext.todo',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.napoleon",
17+
"sphinx.ext.todo",
1718
]
1819

1920
# TODO: Please Read!
@@ -23,29 +24,32 @@
2324
# autodoc_mock_imports = ["digitalio", "busio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
30+
}
2731

2832
# Add any paths that contain templates here, relative to this directory.
29-
templates_path = ['_templates']
33+
templates_path = ["_templates"]
3034

31-
source_suffix = '.rst'
35+
source_suffix = ".rst"
3236

3337
# The master toctree document.
34-
master_doc = 'index'
38+
master_doc = "index"
3539

3640
# General information about the project.
37-
project = u'Adafruit BLE_BroadcastNet Library'
38-
copyright = u'2020 Scott Shawcroft'
39-
author = u'Scott Shawcroft'
41+
project = "Adafruit BLE_BroadcastNet Library"
42+
copyright = "2020 Scott Shawcroft"
43+
author = "Scott Shawcroft"
4044

4145
# The version info for the project you're documenting, acts as replacement for
4246
# |version| and |release|, also used in various other places throughout the
4347
# built documents.
4448
#
4549
# The short X.Y version.
46-
version = u'1.0'
50+
version = "1.0"
4751
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
52+
release = "1.0"
4953

5054
# The language for content autogenerated by Sphinx. Refer to documentation
5155
# for a list of supported languages.
@@ -57,7 +61,7 @@
5761
# List of patterns, relative to source directory, that match files and
5862
# directories to ignore when looking for source files.
5963
# This patterns also effect to html_static_path and html_extra_path
60-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
64+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6165

6266
# The reST default role (used for this markup: `text`) to use for all
6367
# documents.
@@ -69,7 +73,7 @@
6973
add_function_parentheses = True
7074

7175
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
76+
pygments_style = "sphinx"
7377

7478
# If true, `todo` and `todoList` produce output, else they produce nothing.
7579
todo_include_todos = False
@@ -84,68 +88,76 @@
8488
# The theme to use for HTML and HTML Help pages. See the documentation for
8589
# a list of builtin themes.
8690
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
91+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8892

8993
if not on_rtd: # only import and set the theme if we're building docs locally
9094
try:
9195
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
96+
97+
html_theme = "sphinx_rtd_theme"
98+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
9499
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
100+
html_theme = "default"
101+
html_theme_path = ["."]
97102
else:
98-
html_theme_path = ['.']
103+
html_theme_path = ["."]
99104

100105
# Add any paths that contain custom static files (such as style sheets) here,
101106
# relative to this directory. They are copied after the builtin static files,
102107
# so a file named "default.css" will overwrite the builtin "default.css".
103-
html_static_path = ['_static']
108+
html_static_path = ["_static"]
104109

105110
# The name of an image file (relative to this directory) to use as a favicon of
106111
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107112
# pixels large.
108113
#
109-
html_favicon = '_static/favicon.ico'
114+
html_favicon = "_static/favicon.ico"
110115

111116
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitBle_broadcastnetLibrarydoc'
117+
htmlhelp_basename = "AdafruitBle_broadcastnetLibrarydoc"
113118

114119
# -- Options for LaTeX output ---------------------------------------------
115120

116121
latex_elements = {
117-
# The paper size ('letterpaper' or 'a4paper').
118-
#
119-
# 'papersize': 'letterpaper',
120-
121-
# The font size ('10pt', '11pt' or '12pt').
122-
#
123-
# 'pointsize': '10pt',
124-
125-
# Additional stuff for the LaTeX preamble.
126-
#
127-
# 'preamble': '',
128-
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
122+
# The paper size ('letterpaper' or 'a4paper').
123+
#
124+
# 'papersize': 'letterpaper',
125+
# The font size ('10pt', '11pt' or '12pt').
126+
#
127+
# 'pointsize': '10pt',
128+
# Additional stuff for the LaTeX preamble.
129+
#
130+
# 'preamble': '',
131+
# Latex figure (float) alignment
132+
#
133+
# 'figure_align': 'htbp',
132134
}
133135

134136
# Grouping the document tree into LaTeX files. List of tuples
135137
# (source start file, target name, title,
136138
# author, documentclass [howto, manual, or own class]).
137139
latex_documents = [
138-
(master_doc, 'AdafruitBLE_BroadcastNetLibrary.tex', u'AdafruitBLE_BroadcastNet Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitBLE_BroadcastNetLibrary.tex",
143+
"AdafruitBLE_BroadcastNet Library Documentation",
144+
author,
145+
"manual",
146+
),
140147
]
141148

142149
# -- Options for manual page output ---------------------------------------
143150

144151
# One entry per manual page. List of tuples
145152
# (source start file, name, description, authors, manual section).
146153
man_pages = [
147-
(master_doc, 'AdafruitBLE_BroadcastNetlibrary', u'Adafruit BLE_BroadcastNet Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitBLE_BroadcastNetlibrary",
157+
"Adafruit BLE_BroadcastNet Library Documentation",
158+
[author],
159+
1,
160+
)
149161
]
150162

151163
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +166,13 @@
154166
# (source start file, target name, title, author,
155167
# dir menu entry, description, category)
156168
texinfo_documents = [
157-
(master_doc, 'AdafruitBLE_BroadcastNetLibrary', u'Adafruit BLE_BroadcastNet Library Documentation',
158-
author, 'AdafruitBLE_BroadcastNetLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitBLE_BroadcastNetLibrary",
172+
"Adafruit BLE_BroadcastNet Library Documentation",
173+
author,
174+
"AdafruitBLE_BroadcastNetLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/ble_broadcastnet_battery_level.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
while True:
1414
measurement = adafruit_ble_broadcastnet.AdafruitSensorMeasurement()
15-
battery_voltage = battery.value / 2**16 * divider_ratio * battery.reference_voltage
15+
battery_voltage = (
16+
battery.value / 2 ** 16 * divider_ratio * battery.reference_voltage
17+
)
1618
measurement.battery_voltage = int(battery_voltage * 1000)
1719
measurement.temperature = microcontroller.cpu.temperature
1820
print(measurement)

0 commit comments

Comments
 (0)