Skip to content

Commit 20c4da3

Browse files
authored
Merge pull request #37 from adafruit/pylint-update
Ran black, updated to pylint 2.x
2 parents cd063e5 + 01c7d78 commit 20c4da3

File tree

6 files changed

+129
-100
lines changed

6 files changed

+129
-100
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_dht.py

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,20 @@
3131
import array
3232
import time
3333
from digitalio import DigitalInOut, Pull, Direction
34+
3435
_USE_PULSEIO = False
3536
try:
3637
from pulseio import PulseIn
38+
3739
_USE_PULSEIO = True
3840
except ImportError:
39-
pass # This is OK, we'll try to bitbang it!
41+
pass # This is OK, we'll try to bitbang it!
4042

4143

4244
__version__ = "0.0.0-auto.0"
4345
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git"
4446

47+
4548
class DHTBase:
4649
""" base support for DHT11 and DHT22 devices
4750
"""
@@ -88,7 +91,7 @@ def _pulses_to_binary(self, pulses, start, stop):
8891
bit = 0
8992
if pulses[bit_inx] > self.__hiLevel:
9093
bit = 1
91-
binary = binary<<1 | bit
94+
binary = binary << 1 | bit
9295

9396
hi_sig = not hi_sig
9497

@@ -104,7 +107,7 @@ def _get_pulses_pulseio(self):
104107
transition times starting with a low transition time. Normally
105108
pulses will have 81 elements for the DHT11/22 type devices.
106109
"""
107-
pulses = array.array('H')
110+
pulses = array.array("H")
108111
if _USE_PULSEIO:
109112
# The DHT type device use a specialize 1-wire protocol
110113
# The microprocessor first sends a LOW signal for a
@@ -133,7 +136,7 @@ def _get_pulses_bitbang(self):
133136
transition times starting with a low transition time. Normally
134137
pulses will have 81 elements for the DHT11/22 type devices.
135138
"""
136-
pulses = array.array('H')
139+
pulses = array.array("H")
137140
with DigitalInOut(self._pin) as dhtpin:
138141
# we will bitbang if no pulsein capability
139142
transitions = []
@@ -143,19 +146,19 @@ def _get_pulses_bitbang(self):
143146
time.sleep(0.1)
144147
dhtpin.value = False
145148
time.sleep(0.001)
146-
timestamp = time.monotonic() # take timestamp
147-
dhtval = True # start with dht pin true because its pulled up
149+
timestamp = time.monotonic() # take timestamp
150+
dhtval = True # start with dht pin true because its pulled up
148151
dhtpin.direction = Direction.INPUT
149152
dhtpin.pull = Pull.UP
150153
while time.monotonic() - timestamp < 0.25:
151154
if dhtval != dhtpin.value:
152155
dhtval = not dhtval # we toggled
153-
transitions.append(time.monotonic()) # save the timestamp
156+
transitions.append(time.monotonic()) # save the timestamp
154157
# convert transtions to microsecond delta pulses:
155158
# use last 81 pulses
156159
transition_start = max(1, len(transitions) - 81)
157160
for i in range(transition_start, len(transitions)):
158-
pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1]))
161+
pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i - 1]))
159162
pulses.append(min(pulses_micro_sec, 65535))
160163
return pulses
161164

@@ -171,20 +174,24 @@ def measure(self):
171174
# Initiate new reading if this is the first call or if sufficient delay
172175
# If delay not sufficient - return previous reading.
173176
# This allows back to back access for temperature and humidity for same reading
174-
if (self._last_called == 0 or
175-
(time.monotonic()-self._last_called) > delay_between_readings):
177+
if (
178+
self._last_called == 0
179+
or (time.monotonic() - self._last_called) > delay_between_readings
180+
):
176181
self._last_called = time.monotonic()
177182

178183
if _USE_PULSEIO:
179184
pulses = self._get_pulses_pulseio()
180185
else:
181186
pulses = self._get_pulses_bitbang()
182-
#print(len(pulses), "pulses:", [x for x in pulses])
187+
# print(len(pulses), "pulses:", [x for x in pulses])
183188

184189
if len(pulses) >= 80:
185-
buf = array.array('B')
190+
buf = array.array("B")
186191
for byte_start in range(0, 80, 16):
187-
buf.append(self._pulses_to_binary(pulses, byte_start, byte_start+16))
192+
buf.append(
193+
self._pulses_to_binary(pulses, byte_start, byte_start + 16)
194+
)
188195

189196
if self._dht11:
190197
# humidity is 1 byte
@@ -193,10 +200,10 @@ def measure(self):
193200
self._temperature = buf[2]
194201
else:
195202
# humidity is 2 bytes
196-
self._humidity = ((buf[0]<<8) | buf[1]) / 10
203+
self._humidity = ((buf[0] << 8) | buf[1]) / 10
197204
# temperature is 2 bytes
198205
# MSB is sign, bits 0-14 are magnitude)
199-
raw_temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10
206+
raw_temperature = (((buf[2] & 0x7F) << 8) | buf[3]) / 10
200207
# set sign
201208
if buf[2] & 0x80:
202209
raw_temperature = -raw_temperature
@@ -207,7 +214,7 @@ def measure(self):
207214
chk_sum += b
208215

209216
# checksum is the last byte
210-
if chk_sum & 0xff != buf[4]:
217+
if chk_sum & 0xFF != buf[4]:
211218
# check sum failed to validate
212219
raise RuntimeError("Checksum did not validate. Try again.")
213220

@@ -217,6 +224,7 @@ def measure(self):
217224
else:
218225
# Probably a connection issue!
219226
raise RuntimeError("DHT sensor not found, check wiring")
227+
220228
@property
221229
def temperature(self):
222230
""" temperature current reading. It makes sure a reading is available
@@ -237,11 +245,13 @@ def humidity(self):
237245
self.measure()
238246
return self._humidity
239247

248+
240249
class DHT11(DHTBase):
241250
""" Support for DHT11 device.
242251
243252
:param ~board.Pin pin: digital pin used for communication
244253
"""
254+
245255
def __init__(self, pin):
246256
super().__init__(True, pin, 18000)
247257

@@ -251,5 +261,6 @@ class DHT22(DHTBase):
251261
252262
:param ~board.Pin pin: digital pin used for communication
253263
"""
264+
254265
def __init__(self, pin):
255266
super().__init__(False, pin, 1000)

docs/conf.py

Lines changed: 72 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,56 @@
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.viewcode',
14+
"sphinx.ext.autodoc",
15+
"sphinx.ext.intersphinx",
16+
"sphinx.ext.viewcode",
1617
]
1718

1819
autodoc_mock_imports = ["pulseio"]
1920

20-
intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),
21-
'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None),
22-
'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None),
23-
'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)}
21+
intersphinx_mapping = {
22+
"python": ("https://docs.python.org/3.4", None),
23+
"BusDevice": (
24+
"https://circuitpython.readthedocs.io/projects/busdevice/en/latest/",
25+
None,
26+
),
27+
"Register": (
28+
"https://circuitpython.readthedocs.io/projects/register/en/latest/",
29+
None,
30+
),
31+
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
32+
}
2433

2534
# Add any paths that contain templates here, relative to this directory.
26-
templates_path = ['_templates']
35+
templates_path = ["_templates"]
2736

28-
source_suffix = '.rst'
37+
source_suffix = ".rst"
2938

3039
# The master toctree document.
31-
master_doc = 'index'
40+
master_doc = "index"
3241

3342
# General information about the project.
34-
project = u'Adafruit CircuitPython DHT Library'
35-
copyright = u'2017 Mike McWethy'
36-
author = u'Mike McWethy'
43+
project = u"Adafruit CircuitPython DHT Library"
44+
copyright = u"2017 Mike McWethy"
45+
author = u"Mike McWethy"
3746

3847
# The version info for the project you're documenting, acts as replacement for
3948
# |version| and |release|, also used in various other places throughout the
4049
# built documents.
4150
#
4251
# The short X.Y version.
43-
version = u'1.0'
52+
version = u"1.0"
4453
# The full version, including alpha/beta/rc tags.
45-
release = u'1.0'
54+
release = u"1.0"
4655

4756
# The language for content autogenerated by Sphinx. Refer to documentation
4857
# for a list of supported languages.
@@ -54,7 +63,7 @@
5463
# List of patterns, relative to source directory, that match files and
5564
# directories to ignore when looking for source files.
5665
# This patterns also effect to html_static_path and html_extra_path
57-
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md']
66+
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"]
5867

5968
# The reST default role (used for this markup: `text`) to use for all
6069
# documents.
@@ -66,7 +75,7 @@
6675
add_function_parentheses = True
6776

6877
# The name of the Pygments (syntax highlighting) style to use.
69-
pygments_style = 'sphinx'
78+
pygments_style = "sphinx"
7079

7180
# If true, `todo` and `todoList` produce output, else they produce nothing.
7281
todo_include_todos = False
@@ -80,68 +89,76 @@
8089
# The theme to use for HTML and HTML Help pages. See the documentation for
8190
# a list of builtin themes.
8291
#
83-
on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
92+
on_rtd = os.environ.get("READTHEDOCS", None) == "True"
8493

8594
if not on_rtd: # only import and set the theme if we're building docs locally
8695
try:
8796
import sphinx_rtd_theme
88-
html_theme = 'sphinx_rtd_theme'
89-
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.']
97+
98+
html_theme = "sphinx_rtd_theme"
99+
html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."]
90100
except:
91-
html_theme = 'default'
92-
html_theme_path = ['.']
101+
html_theme = "default"
102+
html_theme_path = ["."]
93103
else:
94-
html_theme_path = ['.']
104+
html_theme_path = ["."]
95105

96106
# Add any paths that contain custom static files (such as style sheets) here,
97107
# relative to this directory. They are copied after the builtin static files,
98108
# so a file named "default.css" will overwrite the builtin "default.css".
99-
html_static_path = ['_static']
109+
html_static_path = ["_static"]
100110

101111
# The name of an image file (relative to this directory) to use as a favicon of
102112
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
103113
# pixels large.
104114
#
105-
html_favicon = '_static/favicon.ico'
115+
html_favicon = "_static/favicon.ico"
106116

107117
# Output file base name for HTML help builder.
108-
htmlhelp_basename = 'AdafruitCircuitPythonDHTLibrarydoc'
118+
htmlhelp_basename = "AdafruitCircuitPythonDHTLibrarydoc"
109119

110120
# -- Options for LaTeX output ---------------------------------------------
111121

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

130137
# Grouping the document tree into LaTeX files. List of tuples
131138
# (source start file, target name, title,
132139
# author, documentclass [howto, manual, or own class]).
133140
latex_documents = [
134-
(master_doc, 'AdafruitCircuitPythonDHTLibrary.tex', u'Adafruit CircuitPython DHT Library Documentation',
135-
author, 'manual'),
141+
(
142+
master_doc,
143+
"AdafruitCircuitPythonDHTLibrary.tex",
144+
u"Adafruit CircuitPython DHT Library Documentation",
145+
author,
146+
"manual",
147+
),
136148
]
137149

138150
# -- Options for manual page output ---------------------------------------
139151

140152
# One entry per manual page. List of tuples
141153
# (source start file, name, description, authors, manual section).
142154
man_pages = [
143-
(master_doc, 'adafruitCircuitPythonDHTlibrary', u'Adafruit CircuitPython DHT Library Documentation',
144-
[author], 1)
155+
(
156+
master_doc,
157+
"adafruitCircuitPythonDHTlibrary",
158+
u"Adafruit CircuitPython DHT Library Documentation",
159+
[author],
160+
1,
161+
)
145162
]
146163

147164
# -- Options for Texinfo output -------------------------------------------
@@ -150,7 +167,13 @@
150167
# (source start file, target name, title, author,
151168
# dir menu entry, description, category)
152169
texinfo_documents = [
153-
(master_doc, 'AdafruitCircuitPythonDHTLibrary', u'Adafruit CircuitPython DHT Library Documentation',
154-
author, 'AdafruitCircuitPythonDHTLibrary', 'One line description of project.',
155-
'Miscellaneous'),
170+
(
171+
master_doc,
172+
"AdafruitCircuitPythonDHTLibrary",
173+
u"Adafruit CircuitPython DHT Library Documentation",
174+
author,
175+
"AdafruitCircuitPythonDHTLibrary",
176+
"One line description of project.",
177+
"Miscellaneous",
178+
),
156179
]

examples/dht_simpletest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
temperature_c = dhtDevice.temperature
1212
temperature_f = temperature_c * (9 / 5) + 32
1313
humidity = dhtDevice.humidity
14-
print("Temp: {:.1f} F / {:.1f} C Humidity: {}% "
15-
.format(temperature_f, temperature_c, humidity))
14+
print(
15+
"Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format(
16+
temperature_f, temperature_c, humidity
17+
)
18+
)
1619

1720
except RuntimeError as error:
1821
# Errors happen fairly often, DHT's are hard to read, just keep going

0 commit comments

Comments
 (0)