Skip to content

Commit 3904097

Browse files
committed
Ran black, updated to pylint 2.x
1 parent 81f5760 commit 3904097

File tree

5 files changed

+123
-98
lines changed

5 files changed

+123
-98
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
source actions-ci/install.sh
4141
- name: Pip install pylint, black, & Sphinx
4242
run: |
43-
pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme
43+
pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme
4444
- name: Library version
4545
run: git describe --dirty --always --tags
4646
- name: PyLint

adafruit_tmp006.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
_TMP006_CFG_DRDYEN = const(0x0100)
7272
_TMP006_CFG_DRDY = const(0x0080)
7373

74+
7475
class TMP006:
7576
"""Class to represent an Adafruit TMP006 non-contact temperature measurement
7677
board.
@@ -84,19 +85,26 @@ class TMP006:
8485
def __init__(self, i2c, address=_TMP006_I2CADDR, samplerate=CFG_16SAMPLE):
8586
self._device = I2CDevice(i2c, address)
8687
self._write_u16(_TMP006_CONFIG, _TMP006_CFG_RESET)
87-
time.sleep(.5)
88-
if samplerate not in (CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE,
89-
CFG_16SAMPLE):
90-
raise ValueError('Unexpected samplerate value! Must be one of: ' \
91-
'CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE, or CFG_16SAMPLE')
88+
time.sleep(0.5)
89+
if samplerate not in (
90+
CFG_1SAMPLE,
91+
CFG_2SAMPLE,
92+
CFG_4SAMPLE,
93+
CFG_8SAMPLE,
94+
CFG_16SAMPLE,
95+
):
96+
raise ValueError(
97+
"Unexpected samplerate value! Must be one of: "
98+
"CFG_1SAMPLE, CFG_2SAMPLE, CFG_4SAMPLE, CFG_8SAMPLE, or CFG_16SAMPLE"
99+
)
92100
# Set configuration register to turn on chip, enable data ready output,
93101
# and start sampling at the specified rate.
94102
config = _TMP006_CFG_MODEON | _TMP006_CFG_DRDYEN | samplerate
95103
self._write_u16(_TMP006_CONFIG, config)
96104
# Check device ID match expected value.
97105
dev_id = self.read_register(_TMP006_DEVID)
98106
if dev_id != 0x67:
99-
raise RuntimeError('Init failed - Did not find TMP006')
107+
raise RuntimeError("Init failed - Did not find TMP006")
100108

101109
@property
102110
def active(self):
@@ -117,13 +125,13 @@ def temperature(self):
117125
# pylint: disable=bad-whitespace, invalid-name, too-many-locals
118126
"""Read object temperature from TMP006 sensor."""
119127
if not self.active:
120-
raise RuntimeError('Can not read from sensor when inactive.')
128+
raise RuntimeError("Can not read from sensor when inactive.")
121129
while not self._data_ready():
122130
pass
123131
vobj = self._read_sensor_voltage()
124-
tamb = self._read_die_temperature() + 273.15 # to kelvin
132+
tamb = self._read_die_temperature() + 273.15 # to kelvin
125133
# see TMP006 User Guide, section 5.1
126-
S0 = 6.4e-14 # nominal value
134+
S0 = 6.4e-14 # nominal value
127135
a1 = 1.75e-3
128136
a2 = -1.678e-5
129137
TREF = 298.15
@@ -132,36 +140,36 @@ def temperature(self):
132140
b2 = 4.63e-9
133141
c2 = 13.4
134142

135-
S = S0 * (1 + a1*(tamb - TREF) + a2*(tamb - TREF)**2)
136-
VOS = b0 + b1*(tamb - TREF) + b2*(tamb - TREF)**2
137-
fVOBJ = (vobj - VOS) + c2*(vobj - VOS)**2
143+
S = S0 * (1 + a1 * (tamb - TREF) + a2 * (tamb - TREF) ** 2)
144+
VOS = b0 + b1 * (tamb - TREF) + b2 * (tamb - TREF) ** 2
145+
fVOBJ = (vobj - VOS) + c2 * (vobj - VOS) ** 2
138146

139-
TOBJ = (tamb**4 + (fVOBJ/S))**0.25
147+
TOBJ = (tamb ** 4 + (fVOBJ / S)) ** 0.25
140148

141-
return TOBJ - 273.15 # back to celsius
149+
return TOBJ - 273.15 # back to celsius
142150

143151
def _data_ready(self):
144152
return (self.read_register(_TMP006_CONFIG) & _TMP006_CFG_DRDY) != 0
145153

146154
def _read_sensor_voltage(self):
147155
vobj = self.read_register(_TMP006_VOBJ)
148-
vobj = struct.unpack(">h", vobj.to_bytes(2, 'big'))[0]
156+
vobj = struct.unpack(">h", vobj.to_bytes(2, "big"))[0]
149157
return vobj * 156.25e-9 # volts
150158

151159
def _read_die_temperature(self):
152160
tamb = self.read_register(_TMP006_TAMB)
153-
tamb = struct.unpack(">h", tamb.to_bytes(2, 'big'))[0]
154-
return (tamb >> 2) / 32. # celsius
161+
tamb = struct.unpack(">h", tamb.to_bytes(2, "big"))[0]
162+
return (tamb >> 2) / 32.0 # celsius
155163

156164
def read_register(self, register):
157165
"""Read sensor Register."""
158-
return self._read_u16(register)
166+
return self._read_u16(register)
159167

160168
def _read_u16(self, address):
161169
with self._device as i2c:
162170
self._BUFFER[0] = address & 0xFF
163171
i2c.write_then_readinto(self._BUFFER, self._BUFFER, out_end=1, in_end=2)
164-
return self._BUFFER[0]<<8 | self._BUFFER[1]
172+
return self._BUFFER[0] << 8 | self._BUFFER[1]
165173

166174
def _write_u16(self, address, val):
167175
with self._device as i2c:

docs/conf.py

Lines changed: 69 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,36 @@
2324
# autodoc_mock_imports = ["digitalio", "busio"]
2425

2526

26-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
27+
intersphinx_mapping = {
28+
"python": ("https://docs.python.org/3.4", None),
29+
"BusDevice": (
30+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
31+
None,
32+
),
33+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
34+
}
2735

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

31-
source_suffix = '.rst'
39+
source_suffix = ".rst"
3240

3341
# The master toctree document.
34-
master_doc = 'index'
42+
master_doc = "index"
3543

3644
# General information about the project.
37-
project = u'Adafruit TMP006 Library'
38-
copyright = u'2018 Carter Nelson'
39-
author = u'Carter Nelson'
45+
project = u"Adafruit TMP006 Library"
46+
copyright = u"2018 Carter Nelson"
47+
author = u"Carter Nelson"
4048

4149
# The version info for the project you're documenting, acts as replacement for
4250
# |version| and |release|, also used in various other places throughout the
4351
# built documents.
4452
#
4553
# The short X.Y version.
46-
version = u'1.0'
54+
version = u"1.0"
4755
# The full version, including alpha/beta/rc tags.
48-
release = u'1.0'
56+
release = u"1.0"
4957

5058
# The language for content autogenerated by Sphinx. Refer to documentation
5159
# for a list of supported languages.
@@ -57,7 +65,7 @@
5765
# List of patterns, relative to source directory, that match files and
5866
# directories to ignore when looking for source files.
5967
# 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']
68+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
6169

6270
# The reST default role (used for this markup: `text`) to use for all
6371
# documents.
@@ -69,7 +77,7 @@
6977
add_function_parentheses = True
7078

7179
# The name of the Pygments (syntax highlighting) style to use.
72-
pygments_style = 'sphinx'
80+
pygments_style = "sphinx"
7381

7482
# If true, `todo` and `todoList` produce output, else they produce nothing.
7583
todo_include_todos = False
@@ -84,68 +92,76 @@
8492
# The theme to use for HTML and HTML Help pages. See the documentation for
8593
# a list of builtin themes.
8694
#
87-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
95+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8896

8997
if not on_rtd: # only import and set the theme if we're building docs locally
9098
try:
9199
import sphinx_rtd_theme
92-
html_theme = 'sphinx_rtd_theme'
93-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
100+
101+
html_theme = "sphinx_rtd_theme"
102+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
94103
except:
95-
html_theme = 'default'
96-
html_theme_path = ['.']
104+
html_theme = "default"
105+
html_theme_path = ["."]
97106
else:
98-
html_theme_path = ['.']
107+
html_theme_path = ["."]
99108

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

105114
# The name of an image file (relative to this directory) to use as a favicon of
106115
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
107116
# pixels large.
108117
#
109-
html_favicon = '_static/favicon.ico'
118+
html_favicon = "_static/favicon.ico"
110119

111120
# Output file base name for HTML help builder.
112-
htmlhelp_basename = 'AdafruitTmp006Librarydoc'
121+
htmlhelp_basename = "AdafruitTmp006Librarydoc"
113122

114123
# -- Options for LaTeX output ---------------------------------------------
115124

116125
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',
126+
# The paper size ('letterpaper' or 'a4paper').
127+
#
128+
# 'papersize': 'letterpaper',
129+
# The font size ('10pt', '11pt' or '12pt').
130+
#
131+
# 'pointsize': '10pt',
132+
# Additional stuff for the LaTeX preamble.
133+
#
134+
# 'preamble': '',
135+
# Latex figure (float) alignment
136+
#
137+
# 'figure_align': 'htbp',
132138
}
133139

134140
# Grouping the document tree into LaTeX files. List of tuples
135141
# (source start file, target name, title,
136142
# author, documentclass [howto, manual, or own class]).
137143
latex_documents = [
138-
(master_doc, 'AdafruitTMP006Library.tex', u'AdafruitTMP006 Library Documentation',
139-
author, 'manual'),
144+
(
145+
master_doc,
146+
"AdafruitTMP006Library.tex",
147+
u"AdafruitTMP006 Library Documentation",
148+
author,
149+
"manual",
150+
),
140151
]
141152

142153
# -- Options for manual page output ---------------------------------------
143154

144155
# One entry per manual page. List of tuples
145156
# (source start file, name, description, authors, manual section).
146157
man_pages = [
147-
(master_doc, 'AdafruitTMP006library', u'Adafruit TMP006 Library Documentation',
148-
[author], 1)
158+
(
159+
master_doc,
160+
"AdafruitTMP006library",
161+
u"Adafruit TMP006 Library Documentation",
162+
[author],
163+
1,
164+
)
149165
]
150166

151167
# -- Options for Texinfo output -------------------------------------------
@@ -154,7 +170,13 @@
154170
# (source start file, target name, title, author,
155171
# dir menu entry, description, category)
156172
texinfo_documents = [
157-
(master_doc, 'AdafruitTMP006Library', u'Adafruit TMP006 Library Documentation',
158-
author, 'AdafruitTMP006Library', 'One line description of project.',
159-
'Miscellaneous'),
173+
(
174+
master_doc,
175+
"AdafruitTMP006Library",
176+
u"Adafruit TMP006 Library Documentation",
177+
author,
178+
"AdafruitTMP006Library",
179+
"One line description of project.",
180+
"Miscellaneous",
181+
),
160182
]

examples/tmp006_simpletest.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
def c_to_f(c):
88
return c * 9.0 / 5.0 + 32.0
99

10+
1011
# Create library object using our Bus I2C port
1112
i2c = busio.I2C(board.SCL, board.SDA)
1213
sensor = adafruit_tmp006.TMP006(i2c)
@@ -16,5 +17,7 @@ def c_to_f(c):
1617
# The first sample will be meaningless
1718
while True:
1819
obj_temp = sensor.temperature
19-
print('Object temperature: {0:0.3F}*C / {1:0.3F}*F'.format(obj_temp, c_to_f(obj_temp)))
20+
print(
21+
"Object temperature: {0:0.3F}*C / {1:0.3F}*F".format(obj_temp, c_to_f(obj_temp))
22+
)
2023
time.sleep(5.0)

0 commit comments

Comments
 (0)