Skip to content

Commit 0fcf841

Browse files
committed
clean up; pylint
1 parent 14de7c1 commit 0fcf841

File tree

4 files changed

+113
-110
lines changed

4 files changed

+113
-110
lines changed

adafruit_ble_ibbq.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,14 @@ class IBBQService(Service):
9292
_UNITS_CELSIUS_MSG = b"\x02\x00\x00\x00\x00\x00"
9393
_REQUEST_BATTERY_LEVEL_MSG = b"\x08\x24\x00\x00\x00\x00"
9494

95-
@staticmethod
96-
def target_temp_msg(low, high):
97-
return struct.pack("<HH", low, high)
98-
9995
def __init__(self, service=None):
10096
super().__init__(service=service)
101-
self._settings_result_buf = bytearray(self.settings_result.packet_size)
102-
self._realtime_data_buf = bytearray(self.realtime_data.packet_size)
97+
self._settings_result_buf = bytearray(
98+
self.settings_result.packet_size # pylint: disable=no-member
99+
)
100+
self._realtime_data_buf = bytearray(
101+
self.realtime_data.packet_size # pylint: disable=no-member
102+
)
103103

104104
uuid = StandardUUID(0xFFF0)
105105

@@ -127,16 +127,6 @@ def __init__(self, service=None):
127127
)
128128
"""Send control messages here."""
129129

130-
@property
131-
def settings_result_bytes(self):
132-
length = self.settings_result.readinto(self._settings_result_buf)
133-
return self._settings_result_buf[:length]
134-
135-
@property
136-
def realtime_data_bytes(self):
137-
length = self.realtime_data.readinto(self._realtime_data_buf)
138-
return self._realtime_data_buf[:length]
139-
140130
def init(self):
141131
"""Perform initial "pairing", which is not regular BLE pairing."""
142132
self.account_and_verify = self._CREDENTIALS_MSG
@@ -161,13 +151,15 @@ def temperatures(self):
161151
"""Return a tuple of temperatures for all the possible temperature probes on the device.
162152
Temperatures are in degrees Celsius. Unconnected probes return 0.0.
163153
"""
164-
data = self.realtime_data_bytes
165-
if not data:
166-
return None
167-
return tuple(
168-
struct.unpack_from("<H", data, offset=offset)[0] / 10
169-
for offset in range(0, len(data), 2)
170-
)
154+
data = self._realtime_data_buf
155+
length = self.realtime_data.readinto(data) # pylint: disable=no-member
156+
if length > 0:
157+
return tuple(
158+
struct.unpack_from("<H", data, offset=offset)[0] / 10
159+
for offset in range(0, length, 2)
160+
)
161+
# No data.
162+
return None
171163

172164
@property
173165
def battery_level(self):
@@ -176,10 +168,10 @@ def battery_level(self):
176168
actual battery voltage by 0.1v or so.
177169
"""
178170
self.settings_data = self._REQUEST_BATTERY_LEVEL_MSG
179-
result = self.settings_result_bytes
180-
if len(result) >= 5:
181-
# There can be at least one extra byte at the end, so use unpack_from().
182-
header, current_voltage, max_voltage = struct.unpack_from("<BHH", result)
171+
results = self._settings_result_buf
172+
length = self.settings_result.readinto(results) # pylint: disable=no-member
173+
if length >= 5:
174+
header, current_voltage, max_voltage = struct.unpack_from("<BHH", results)
183175
if header == 0x24:
184176
# Calibration was determined empirically, by comparing
185177
# the returned values with actual measurements of battery voltage,
@@ -188,5 +180,5 @@ def battery_level(self):
188180
current_voltage / 2000 - 0.3,
189181
(6550 if max_voltage == 0 else max_voltage) / 2000,
190182
)
191-
# Unexpected response.
183+
# Unexpected response or no data.
192184
return None

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_iBBQ Library'
38-
copyright = u'2020 Adafruit Industries'
39-
author = u'Adafruit Industries'
41+
project = "Adafruit BLE_iBBQ Library"
42+
copyright = "2020 Adafruit Industries"
43+
author = "Adafruit Industries"
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_ibbqLibrarydoc'
117+
htmlhelp_basename = "AdafruitBle_ibbqLibrarydoc"
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_iBBQLibrary.tex', u'AdafruitBLE_iBBQ Library Documentation',
139-
author, 'manual'),
140+
(
141+
master_doc,
142+
"AdafruitBLE_iBBQLibrary.tex",
143+
"AdafruitBLE_iBBQ 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_iBBQlibrary', u'Adafruit BLE_iBBQ Library Documentation',
148-
[author], 1)
154+
(
155+
master_doc,
156+
"AdafruitBLE_iBBQlibrary",
157+
"Adafruit BLE_iBBQ 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_iBBQLibrary', u'Adafruit BLE_iBBQ Library Documentation',
158-
author, 'AdafruitBLE_iBBQLibrary', 'One line description of project.',
159-
'Miscellaneous'),
169+
(
170+
master_doc,
171+
"AdafruitBLE_iBBQLibrary",
172+
"Adafruit BLE_iBBQ Library Documentation",
173+
author,
174+
"AdafruitBLE_iBBQLibrary",
175+
"One line description of project.",
176+
"Miscellaneous",
177+
),
160178
]

examples/ble_ibbq_simpletest.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import adafruit_ble
44
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
5-
from adafruit_ble.services.standard.device_info import DeviceInfoService
65
from adafruit_ble_ibbq import IBBQService
76

87
# PyLint can't find BLERadio for some reason so special case it here.
@@ -26,5 +25,10 @@
2625
ibbq_service = ibbq_connection[IBBQService]
2726
ibbq_service.init()
2827
while ibbq_connection.connected:
29-
print(ibbq_service.temperatures, ibbq_service.battery_level)
30-
time.sleep(1)
28+
print(
29+
"Temperatures:",
30+
ibbq_service.temperatures,
31+
"; Battery:",
32+
ibbq_service.battery_level,
33+
)
34+
time.sleep(2)

setup.py

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,48 @@
66
"""
77

88
from setuptools import setup, find_packages
9+
910
# To use a consistent encoding
1011
from codecs import open
1112
from os import path
1213

1314
here = path.abspath(path.dirname(__file__))
1415

1516
# Get the long description from the README file
16-
with open(path.join(here, 'README.rst'), encoding='utf-8') as f:
17+
with open(path.join(here, "README.rst"), encoding="utf-8") as f:
1718
long_description = f.read()
1819

1920
setup(
20-
name='adafruit-circuitpython-ble-ibbq',
21-
21+
name="adafruit-circuitpython-ble-ibbq",
2222
use_scm_version=True,
23-
setup_requires=['setuptools_scm'],
24-
25-
description='BLE support for iBBQ thermometers',
23+
setup_requires=["setuptools_scm"],
24+
description="BLE support for iBBQ thermometers",
2625
long_description=long_description,
27-
long_description_content_type='text/x-rst',
28-
26+
long_description_content_type="text/x-rst",
2927
# The project's main homepage.
30-
url='https://github.com/adafruit/Adafruit_CircuitPython_BLE_iBBQ',
31-
28+
url="https://github.com/adafruit/Adafruit_CircuitPython_BLE_iBBQ",
3229
# Author details
33-
author='Adafruit Industries',
34-
author_email='circuitpython@adafruit.com',
35-
36-
install_requires=[
37-
'Adafruit-Blinka',
38-
'adafruit-circuitpython-ble'
39-
],
40-
30+
author="Adafruit Industries",
31+
author_email="circuitpython@adafruit.com",
32+
install_requires=["Adafruit-Blinka", "adafruit-circuitpython-ble"],
4133
# Choose your license
42-
license='MIT',
43-
34+
license="MIT",
4435
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
4536
classifiers=[
46-
'Development Status :: 3 - Alpha',
47-
'Intended Audience :: Developers',
48-
'Topic :: Software Development :: Libraries',
49-
'Topic :: System :: Hardware',
50-
'License :: OSI Approved :: MIT License',
51-
'Programming Language :: Python :: 3',
52-
'Programming Language :: Python :: 3.4',
53-
'Programming Language :: Python :: 3.5',
37+
"Development Status :: 3 - Alpha",
38+
"Intended Audience :: Developers",
39+
"Topic :: Software Development :: Libraries",
40+
"Topic :: System :: Hardware",
41+
"License :: OSI Approved :: MIT License",
42+
"Programming Language :: Python :: 3",
43+
"Programming Language :: Python :: 3.4",
44+
"Programming Language :: Python :: 3.5",
5445
],
55-
5646
# What does your project relate to?
57-
keywords='adafruit blinka circuitpython micropython ble_ibbq ble ibbq thermometer',
58-
47+
keywords="adafruit blinka circuitpython micropython ble_ibbq ble ibbq thermometer",
5948
# You can just specify the packages manually here if your project is
6049
# simple. Or you can use find_packages().
6150
# TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER,
6251
# CHANGE `py_modules=['...']` TO `packages=['...']`
63-
py_modules=['adafruit_ble_ibbq'],
52+
py_modules=["adafruit_ble_ibbq"],
6453
)

0 commit comments

Comments
 (0)