From e129bdb18bc058e07f1e6b2bb13e91a41fcf79cc Mon Sep 17 00:00:00 2001 From: Tony DiCola Date: Fri, 20 Oct 2017 14:04:07 -0700 Subject: [PATCH 001/153] Add travis config for mpy generation. --- .travis.yml | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..d56d250 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,56 @@ +# Travis CI configuration for automated .mpy file generation. +# Author: Tony DiCola +# License: Public Domain +# This configuration will work with Travis CI (travis-ci.org) to automacially +# build .mpy files for MicroPython when a new tagged release is created. This +# file is relatively generic and can be shared across multiple repositories by +# following these steps: +# 1. Copy this file into a .travis.yml file in the root of the repository. +# 2. Change the deploy > file section below to list each of the .mpy files +# that should be generated. The config will automatically look for +# .py files with the same name as the source for generating the .mpy files. +# Note that the .mpy extension should be lower case! +# 3. Commit the .travis.yml file and push it to GitHub. +# 4. Go to travis-ci.org and find the repository (it needs to be setup to access +# your github account, and your github account needs access to write to the +# repo). Flip the 'ON' switch on for Travis and the repo, see the Travis +# docs for more details: https://docs.travis-ci.com/user/getting-started/ +# 5. Get a GitHub 'personal access token' which has at least 'public_repo' or +# 'repo' scope: https://help.github.com/articles/creating-an-access-token-for-command-line-use/ +# Keep this token safe and secure! Anyone with the token will be able to +# access and write to your GitHub repositories. Travis will use the token +# to attach the .mpy files to the release. +# 6. In the Travis CI settings for the repository that was enabled find the +# environment variable editing page: https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings +# Add an environment variable named GITHUB_TOKEN and set it to the value +# of the GitHub personal access token above. Keep 'Display value in build +# log' flipped off. +# 7. That's it! Tag a release and Travis should go to work to add .mpy files +# to the release. It takes about a 2-3 minutes for a worker to spin up, +# build mpy-cross, and add the binaries to the release. +language: generic + +sudo: true + +deploy: + provider: releases + api_key: $GITHUB_TOKEN + file: + - "adafruit_dht.mpy" + skip_cleanup: true + on: + tags: true + +before_install: +- sudo apt-get -yqq update +- sudo apt-get install -y build-essential git python python-pip +- git clone https://github.com/adafruit/micropython.git +- cd micropython +- git checkout stable +- cd .. +- make -C micropython/mpy-cross +- export PATH=$PATH:$PWD/micropython/mpy-cross/ +- sudo pip install shyaml + +before_deploy: +- shyaml get-values deploy.file < .travis.yml | sed 's/.mpy/.py/' | xargs -L1 mpy-cross From 0feedd0d09858cf366324400107b35e738ab34d8 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Sat, 9 Dec 2017 05:32:19 -0700 Subject: [PATCH 002/153] Added pylint to project with update to code --- .gitignore | 4 + .pylintrc | 432 ++++++++++++++++++++++++++++++++++++ .travis.yml | 30 +++ adafruit_dht.py | 7 +- examples/dhttoleddisplay.py | 11 +- 5 files changed, 474 insertions(+), 10 deletions(-) create mode 100644 .gitignore create mode 100644 .pylintrc create mode 100644 .travis.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5b5b0c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.env +build* +bundles + diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000..e274ba9 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,432 @@ +[MASTER] + +# A comma-separated list of package or module names from where C extensions may +# be loaded. Extensions are loading into the active Python interpreter and may +# run arbitrary code +extension-pkg-whitelist= + +# Add files or directories to the blacklist. They should be base names, not +# paths. +ignore=CVS + +# Add files or directories matching the regex patterns to the blacklist. The +# regex matches against base names, not paths. +ignore-patterns= + +# Python code to execute, usually for sys.path manipulation such as +# pygtk.require(). +#init-hook= + +# Use multiple processes to speed up Pylint. +# jobs=1 +jobs=2 + +# List of plugins (as comma separated values of python modules names) to load, +# usually to register additional checkers. +load-plugins= + +# Pickle collected data for later comparisons. +persistent=yes + +# Specify a configuration file. +#rcfile= + +# Allow loading of arbitrary C extensions. Extensions are imported into the +# active Python interpreter and may run arbitrary code. +unsafe-load-any-extension=no + + +[MESSAGES CONTROL] + +# Only show warnings with the listed confidence levels. Leave empty to show +# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED +confidence= + +# Disable the message, report, category or checker with the given id(s). You +# can either give multiple identifiers separated by comma (,) or put this +# option multiple times (only on the command line, not in the configuration +# file where it should appear only once).You can also use "--disable=all" to +# disable everything first and then reenable specific checks. For example, if +# you want to run only the similarities checker, you can use "--disable=all +# --enable=similarities". If you want to run only the classes checker, but have +# no Warning level messages displayed, use"--disable=all --enable=classes +# --disable=W" +# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error + +# Enable the message, report, category or checker with the given id(s). You can +# either give multiple identifier separated by comma (,) or put this option +# multiple time (only on the command line, not in the configuration file where +# it should appear only once). See also the "--disable" option for examples. +enable= + + +[REPORTS] + +# Python expression which should return a note less than 10 (10 is the highest +# note). You have access to the variables errors warning, statement which +# respectively contain the number of errors / warnings messages and the total +# number of statements analyzed. This is used by the global evaluation report +# (RP0004). +evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) + +# Template used to display messages. This is a python new-style format string +# used to format the message information. See doc for all details +#msg-template= + +# Set the output format. Available formats are text, parseable, colorized, json +# and msvs (visual studio).You can also give a reporter class, eg +# mypackage.mymodule.MyReporterClass. +output-format=text + +# Tells whether to display a full report or only the messages +reports=no + +# Activate the evaluation score. +score=yes + + +[REFACTORING] + +# Maximum number of nested blocks for function / method body +max-nested-blocks=5 + + +[LOGGING] + +# Logging modules to check that the string format arguments are in logging +# function parameter format +logging-modules=logging + + +[SPELLING] + +# Spelling dictionary name. Available dictionaries: none. To make it working +# install python-enchant package. +spelling-dict= + +# List of comma separated words that should not be checked. +spelling-ignore-words= + +# A path to a file that contains private dictionary; one word per line. +spelling-private-dict-file= + +# Tells whether to store unknown words to indicated private dictionary in +# --spelling-private-dict-file option instead of raising a message. +spelling-store-unknown-words=no + + +[MISCELLANEOUS] + +# List of note tags to take in consideration, separated by a comma. +notes=FIXME,XXX,TODO + + +[TYPECHECK] + +# List of decorators that produce context managers, such as +# contextlib.contextmanager. Add to this list to register other decorators that +# produce valid context managers. +contextmanager-decorators=contextlib.contextmanager + +# List of members which are set dynamically and missed by pylint inference +# system, and so shouldn't trigger E1101 when accessed. Python regular +# expressions are accepted. +generated-members= + +# Tells whether missing members accessed in mixin class should be ignored. A +# mixin class is detected if its name ends with "mixin" (case insensitive). +ignore-mixin-members=yes + +# This flag controls whether pylint should warn about no-member and similar +# checks whenever an opaque object is returned when inferring. The inference +# can return multiple potential results while evaluating a Python object, but +# some branches might not be evaluated, which results in partial inference. In +# that case, it might be useful to still emit no-member and other checks for +# the rest of the inferred objects. +ignore-on-opaque-inference=yes + +# List of class names for which member attributes should not be checked (useful +# for classes with dynamically set attributes). This supports the use of +# qualified names. +ignored-classes=optparse.Values,thread._local,_thread._local + +# List of module names for which member attributes should not be checked +# (useful for modules/projects where namespaces are manipulated during runtime +# and thus existing member attributes cannot be deduced by static analysis. It +# supports qualified module names, as well as Unix pattern matching. +ignored-modules= + +# Show a hint with possible names when a member name was not found. The aspect +# of finding the hint is based on edit distance. +missing-member-hint=yes + +# The minimum edit distance a name should have in order to be considered a +# similar match for a missing member name. +missing-member-hint-distance=1 + +# The total number of similar names that should be taken in consideration when +# showing a hint for a missing member. +missing-member-max-choices=1 + + +[VARIABLES] + +# List of additional names supposed to be defined in builtins. Remember that +# you should avoid to define new builtins when possible. +additional-builtins= + +# Tells whether unused global variables should be treated as a violation. +allow-global-unused-variables=yes + +# List of strings which can identify a callback function by name. A callback +# name must start or end with one of those strings. +callbacks=cb_,_cb + +# A regular expression matching the name of dummy variables (i.e. expectedly +# not used). +dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ + +# Argument names that match this expression will be ignored. Default to name +# with leading underscore +ignored-argument-names=_.*|^ignored_|^unused_ + +# Tells whether we should check for unused import in __init__ files. +init-import=no + +# List of qualified module names which can have objects that can redefine +# builtins. +redefining-builtins-modules=six.moves,future.builtins + + +[FORMAT] + +# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. +# expected-line-ending-format= +expected-line-ending-format=LF + +# Regexp for a line that is allowed to be longer than the limit. +ignore-long-lines=^\s*(# )??$ + +# Number of spaces of indent required inside a hanging or continued line. +indent-after-paren=4 + +# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 +# tab). +indent-string=' ' + +# Maximum number of characters on a single line. +max-line-length=100 + +# Maximum number of lines in a module +max-module-lines=1000 + +# List of optional constructs for which whitespace checking is disabled. `dict- +# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. +# `trailing-comma` allows a space between comma and closing bracket: (a, ). +# `empty-line` allows space-only lines. +no-space-check=trailing-comma,dict-separator + +# Allow the body of a class to be on the same line as the declaration if body +# contains single statement. +single-line-class-stmt=no + +# Allow the body of an if to be on the same line as the test if there is no +# else. +single-line-if-stmt=no + + +[SIMILARITIES] + +# Ignore comments when computing similarities. +ignore-comments=yes + +# Ignore docstrings when computing similarities. +ignore-docstrings=yes + +# Ignore imports when computing similarities. +ignore-imports=no + +# Minimum lines number of a similarity. +min-similarity-lines=4 + + +[BASIC] + +# Naming hint for argument names +argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct argument names +argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for attribute names +attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct attribute names +attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Bad variable names which should always be refused, separated by a comma +bad-names=foo,bar,baz,toto,tutu,tata + +# Naming hint for class attribute names +class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Regular expression matching correct class attribute names +class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ + +# Naming hint for class names +# class-name-hint=[A-Z_][a-zA-Z0-9]+$ +class-name-hint=[A-Z_][a-zA-Z0-9_]+$ + +# Regular expression matching correct class names +# class-rgx=[A-Z_][a-zA-Z0-9]+$ +class-rgx=[A-Z_][a-zA-Z0-9_]+$ + +# Naming hint for constant names +const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Regular expression matching correct constant names +const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ + +# Minimum line length for functions/classes that require docstrings, shorter +# ones are exempt. +docstring-min-length=-1 + +# Naming hint for function names +function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct function names +function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Good variable names which should always be accepted, separated by a comma +# good-names=i,j,k,ex,Run,_ +good-names=r,g,b,i,j,k,n,ex,Run,_ + +# Include a hint for the correct naming format with invalid-name +include-naming-hint=no + +# Naming hint for inline iteration names +inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ + +# Regular expression matching correct inline iteration names +inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ + +# Naming hint for method names +method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct method names +method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Naming hint for module names +module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Regular expression matching correct module names +module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ + +# Colon-delimited sets of names that determine each other's naming style when +# the name regexes allow several styles. +name-group= + +# Regular expression which should only match function or class names that do +# not require a docstring. +no-docstring-rgx=^_ + +# List of decorators that produce properties, such as abc.abstractproperty. Add +# to this list to register other decorators that produce valid properties. +property-classes=abc.abstractproperty + +# Naming hint for variable names +variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + +# Regular expression matching correct variable names +variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ + + +[IMPORTS] + +# Allow wildcard imports from modules that define __all__. +allow-wildcard-with-all=no + +# Analyse import fallback blocks. This can be used to support both Python 2 and +# 3 compatible code, which means that the block might have code that exists +# only in one or another interpreter, leading to false positives when analysed. +analyse-fallback-blocks=no + +# Deprecated modules which should not be used, separated by a comma +deprecated-modules=optparse,tkinter.tix + +# Create a graph of external dependencies in the given file (report RP0402 must +# not be disabled) +ext-import-graph= + +# Create a graph of every (i.e. internal and external) dependencies in the +# given file (report RP0402 must not be disabled) +import-graph= + +# Create a graph of internal dependencies in the given file (report RP0402 must +# not be disabled) +int-import-graph= + +# Force import order to recognize a module as part of the standard +# compatibility libraries. +known-standard-library= + +# Force import order to recognize a module as part of a third party library. +known-third-party=enchant + + +[CLASSES] + +# List of method names used to declare (i.e. assign) instance attributes. +defining-attr-methods=__init__,__new__,setUp + +# List of member names, which should be excluded from the protected access +# warning. +exclude-protected=_asdict,_fields,_replace,_source,_make + +# List of valid names for the first argument in a class method. +valid-classmethod-first-arg=cls + +# List of valid names for the first argument in a metaclass class method. +valid-metaclass-classmethod-first-arg=mcs + + +[DESIGN] + +# Maximum number of arguments for function / method +max-args=5 + +# Maximum number of attributes for a class (see R0902). +# max-attributes=7 +max-attributes=11 + +# Maximum number of boolean expressions in a if statement +max-bool-expr=5 + +# Maximum number of branch for function / method body +max-branches=12 + +# Maximum number of locals for function / method body +max-locals=15 + +# Maximum number of parents for a class (see R0901). +max-parents=7 + +# Maximum number of public methods for a class (see R0904). +max-public-methods=20 + +# Maximum number of return / yield for function / method body +max-returns=6 + +# Maximum number of statements in function / method body +max-statements=50 + +# Minimum number of public methods for a class (see R0903). +min-public-methods=2 + + +[EXCEPTIONS] + +# Exceptions that will emit a warning when being caught. Defaults to +# "Exception" +overgeneral-exceptions=Exception diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..87ea816 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,30 @@ +# This is a common .travis.yml for generating library release zip files for +# CircuitPython library releases using circuitpython-build-tools. +# See https://github.com/adafruit/circuitpython-build-tools for detailed setup +# instructions. + +dist: trusty +sudo: false +language: python +python: + - "3.6" + +cache: + pip: true + +deploy: + provider: releases + api_key: $GITHUB_TOKEN + file_glob: true + file: bundles/* + skip_cleanup: true + on: + tags: true + +install: + - pip install pylint circuitpython-travis-build-tools + +script: + - pylint adafruit_circuitpython_dht.py + - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) + - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . diff --git a/adafruit_dht.py b/adafruit_dht.py index bc9b1f0..78af41d 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -34,7 +34,7 @@ import pulseio except ImportError as excpt: print("adafruit_dht requires the pulseio library, but it failed to load."+ - " Note that CircuitPython does not support pulseio on all boards.") + " Note that CircuitPython does not support pulseio on all boards.") raise excpt class DHTBase: @@ -120,7 +120,7 @@ def _get_pulses(self): break pulse_in.pause() - while len(pulse_in): + while pulse_in: pulses.append(pulse_in.popleft()) pulse_in.resume() @@ -167,7 +167,8 @@ def measure(self): if chk_sum & 0xff != buf[4]: # check sum failed to validate raise RuntimeError("Checksum did not validate. Try again.") - #print("checksum did not match. Temp: {} Humidity: {} Checksum:{}".format(self._temperature,self._humidity,bites[4])) + #print("checksum did not match. Temp: {} Humidity: {} Checksum:{}" + #.format(self._temperature,self._humidity,bites[4])) # checksum matches #print("Temp: {} C Humidity: {}% ".format(self._temperature, self._humidity)) diff --git a/examples/dhttoleddisplay.py b/examples/dhttoleddisplay.py index 9b8ff88..b3b7335 100644 --- a/examples/dhttoleddisplay.py +++ b/examples/dhttoleddisplay.py @@ -3,17 +3,15 @@ and displaying results to the serial port and a 8 digit 7-segment display the DHT device data wire is connected to board.D2 """ -# import for dht devices +# import for dht devices and 7-segment display devices import time import adafruit_dht -from board import D2 - -#imports for 7-segment display device from adafruit_max7219 import bcddigits -from board import TX, RX, A2 import busio import digitalio +from board import D2, TX, RX, A2 + clk = RX din = TX cs = digitalio.DigitalInOut(A2) @@ -33,11 +31,10 @@ # now show the values on the 8 digit 7-segment display display.clear_all() - display.show_str(0,'{:5.1f}{:5.1f}'.format(temperature, humidity)) + display.show_str(0, '{:5.1f}{:5.1f}'.format(temperature, humidity)) display.show() except RuntimeError as error: print(error.args) time.sleep(2.0) - \ No newline at end of file From a9bdb62a60b505594f547e86810ddb4608a690d5 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Sat, 9 Dec 2017 06:08:46 -0700 Subject: [PATCH 003/153] Adding repo info to .py file --- adafruit_dht.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_dht.py b/adafruit_dht.py index 78af41d..f455fe6 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -37,6 +37,9 @@ " Note that CircuitPython does not support pulseio on all boards.") raise excpt +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git" + class DHTBase: """ base support for DHT11 and DHT22 devices """ From bb311b7d41cb6a30c2e522229a6436b7b26243ca Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Sat, 9 Dec 2017 06:21:22 -0700 Subject: [PATCH 004/153] Fixed .yml file --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 87ea816..ee554db 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,6 +25,6 @@ install: - pip install pylint circuitpython-travis-build-tools script: - - pylint adafruit_circuitpython_dht.py + - pylint adafruit_dht.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . From 88dc03012b74fcbcb43ad5613c92ebe17648da75 Mon Sep 17 00:00:00 2001 From: mrmcwethy Date: Sat, 9 Dec 2017 13:36:54 -0700 Subject: [PATCH 005/153] Fixed typo --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index ee554db..65862d3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -22,7 +22,7 @@ deploy: tags: true install: - - pip install pylint circuitpython-travis-build-tools + - pip install pylint circuitpython-build-tools script: - pylint adafruit_dht.py From fd756be7e07dd4db47977aa32f697c64377ab7da Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 19:52:04 -0600 Subject: [PATCH 006/153] added simpletest example --- examples/dht_simpletest.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 examples/dht_simpletest.py diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py new file mode 100644 index 0000000..1947174 --- /dev/null +++ b/examples/dht_simpletest.py @@ -0,0 +1,18 @@ +import time +import adafruit_dht +from board import D2 + +#initial the dht device +dhtDevice = adafruit_dht.DHT22(D2) + +while True: + try: + # show the values to the serial port + temperature = dhtDevice.temperature*9/5+32 + humidity = dhtDevice.humidity + print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) + + except RuntimeError as error: + print(error.args) + + time.sleep(2.0) From d8e0222d6a5e26ba809017587c36a39381daf2bc Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 19:54:09 -0600 Subject: [PATCH 007/153] renamed led display example --- examples/{dhttoleddisplay.py => dht_to_led_display.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename examples/{dhttoleddisplay.py => dht_to_led_display.py} (100%) diff --git a/examples/dhttoleddisplay.py b/examples/dht_to_led_display.py similarity index 100% rename from examples/dhttoleddisplay.py rename to examples/dht_to_led_display.py From 70479e9850458e2c90fea79b619f45cb62350799 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 20:00:22 -0600 Subject: [PATCH 008/153] setup docs folder --- api.rst | 6 ----- docs/_static/favicon.ico | Bin 0 -> 4414 bytes docs/api.rst | 5 ++++ conf.py => docs/conf.py | 15 +++++++++--- docs/examples.rst | 8 +++++++ docs/index.rst | 49 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 9 deletions(-) delete mode 100644 api.rst create mode 100644 docs/_static/favicon.ico create mode 100644 docs/api.rst rename conf.py => docs/conf.py (90%) create mode 100644 docs/examples.rst create mode 100644 docs/index.rst diff --git a/api.rst b/api.rst deleted file mode 100644 index e69910e..0000000 --- a/api.rst +++ /dev/null @@ -1,6 +0,0 @@ - -DHT Libary Documentation -============================ - -.. automodule:: adafruit_dht - :members: diff --git a/docs/_static/favicon.ico b/docs/_static/favicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..5aca98376a1f7e593ebd9cf41a808512c2135635 GIT binary patch literal 4414 zcmd^BX;4#F6n=SG-XmlONeGrD5E6J{RVh+e928U#MG!$jWvO+UsvWh`x&VqGNx*en zx=qox7Dqv{kPwo%fZC$dDwVpRtz{HzTkSs8QhG0)%Y=-3@Kt!4ag|JcIo?$-F|?bXVS9UDUyev>MVZQ(H8K4#;BQW-t2CPorj8^KJrMX}QK zp+e<;4ldpXz~=)2GxNy811&)gt-}Q*yVQpsxr@VMoA##{)$1~=bZ1MmjeFw?uT(`8 z^g=09<=zW%r%buwN%iHtuKSg|+r7HkT0PYN*_u9k1;^Ss-Z!RBfJ?Un4w(awqp2b3 z%+myoFis_lTlCrGx2z$0BQdh+7?!JK#9K9@Z!VrG zNj6gK5r(b4?YDOLw|DPRoN7bdP{(>GEG41YcN~4r_SUHU2hgVtUwZG@s%edC;k7Sn zC)RvEnlq~raE2mY2ko64^m1KQL}3riixh?#J{o)IT+K-RdHae2eRX91-+g!y`8^># z-zI0ir>P%Xon)!@xp-BK2bDYUB9k613NRrY6%lVjbFcQc*pRqiK~8xtkNPLxt}e?&QsTB}^!39t_%Qb)~Ukn0O%iC;zt z<&A-y;3h++)>c1br`5VFM~5(83!HKx$L+my8sW_c#@x*|*vB1yU)_dt3vH;2hqPWx zAl^6@?ipx&U7pf`a*>Yq6C85nb+B=Fnn+(id$W#WB^uHAcZVG`qg;rWB}ubvi(Y>D z$ei>REw$#xp0SHAd^|1hq&9HJ=jKK8^zTH~nk)G?yUcmTh9vUM6Y0LMw4(gYVY$D$ zGl&WY&H<)BbJ&3sYbKjx1j^=3-0Q#f^}(aP1?8^`&FUWMp|rmtpK)bLQ1Zo?^s4jqK=Lfg*9&geMGVQ z#^-*!V`fG@;H&{M9S8%+;|h&Qrxym0Ar>WT4BCVLR8cGXF=JmEYN(sNT(9vl+S|%g z8r7nXQ(95i^`=+XHo|){$vf2$?=`F$^&wFlYXyXg$B{a>$-Fp+V}+D;9k=~Xl~?C4 zAB-;RKXdUzBJE{V&d&%R>aEfFe;vxqI$0@hwVM}gFeQR@j}a>DDxR+n+-*6|_)k%% z*mSpDV|=5I9!&VC&9tD%fcVygWZV!iIo2qFtm#!*(s|@ZT33*Ad;+<|3^+yrp*;oH zBSYLV(H1zTU?2WjrCQoQW)Z>J2a=dTriuvezBmu16`tM2fm7Q@d4^iqII-xFpwHGI zn9CL}QE*1vdj2PX{PIuqOe5dracsciH6OlAZATvE8rj6ykqdIjal2 z0S0S~PwHb-5?OQ-tU-^KTG@XNrEVSvo|HIP?H;7ZhYeZkhSqh-{reE!5di;1zk$#Y zCe7rOnlzFYJ6Z#Hm$GoidKB=2HBCwm`BbZVeZY4ukmG%1uz7p2URs6c9j-Gjj^oQV zsdDb3@k2e`C$1I5ML5U0Qs0C1GAp^?!*`=|Nm(vWz3j*j*8ucum2;r0^-6Aca=Gv) zc%}&;!+_*S2tlnnJnz0EKeRmw-Y!@9ob!XQBwiv}^u9MkaXHvM=!<3YX;+2#5Cj5pp?FEK750S3BgeSDtaE^ zXUM@xoV6yBFKfzvY20V&Lr0yC + + DHT22 basic temperature-humidity sensor + extras + +.. toctree:: + :caption: Other Links + + Download + CircuitPython Reference Documentation + CircuitPython Support Forum + Discord Chat + Adafruit Learning System + Adafruit Blog + Adafruit Store + +Indices and tables +================== + +* :ref:`genindex` +* :ref:`modindex` +* :ref:`search` From 662fe4528733985c935c1462db5d19e99f11ba21 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 20:02:23 -0600 Subject: [PATCH 009/153] updated .travis & .readthedocs yml --- readthedocs.yml => .readthedocs.yml | 2 ++ .travis.yml | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) rename readthedocs.yml => .readthedocs.yml (61%) diff --git a/readthedocs.yml b/.readthedocs.yml similarity index 61% rename from readthedocs.yml rename to .readthedocs.yml index a3a16c1..78a4671 100644 --- a/readthedocs.yml +++ b/.readthedocs.yml @@ -1,2 +1,4 @@ +python: + version: 3 requirements_file: requirements.txt diff --git a/.travis.yml b/.travis.yml index 65862d3..36ca9b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,15 +16,16 @@ deploy: provider: releases api_key: $GITHUB_TOKEN file_glob: true - file: bundles/* + file: $TRAVIS_BUILD_DIR/bundles/* skip_cleanup: true on: tags: true install: - - pip install pylint circuitpython-build-tools + - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme script: - pylint adafruit_dht.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . + - cd docs && sphinx-build -E -W -b html . _build/html From fecbbfa2b9300d73ff2d5435e252bfb425e9af7b Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 20:04:35 -0600 Subject: [PATCH 010/153] updated README --- README.rst | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/README.rst b/README.rst index 08f601d..9afb920 100644 --- a/README.rst +++ b/README.rst @@ -6,9 +6,10 @@ Introduction :target: https://circuitpython.readthedocs.io/projects/dht/en/latest/ :alt: Documentation Status -.. image :: https://badges.gitter.im/adafruit/circuitpython.svg - :target: https://gitter.im/adafruit/circuitpython?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge - :alt: Gitter + +.. image :: https://img.shields.io/discord/327254708534116352.svg + :target: https://discord.gg/nBQh6qu + :alt: Discord CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. @@ -79,10 +80,50 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -API Reference -============= +Building locally +================ + +To build this library locally you'll need to install the +`circuitpython-build-tools `_ package. + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install circuitpython-build-tools + +Once installed, make sure you are in the virtual environment: + +.. code-block:: shell + + source .env/bin/activate + +Then run the build: + +.. code-block:: shell + + circuitpython-build-bundles --filename_prefix adafruit-circuitpython-veml6070 --library_location . + +Sphinx documentation +----------------------- + +Sphinx is used to build the documentation based on rST files and comments in the code. First, +install dependencies (feel free to reuse the virtual environment from above): + +.. code-block:: shell + + python3 -m venv .env + source .env/bin/activate + pip install Sphinx sphinx-rtd-theme + +Now, once you have the virtual environment activated: + +.. code-block:: shell + + cd docs + sphinx-build -E -W -b html . _build/html -.. toctree:: - :maxdepth: 2 +This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to +view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to +locally verify it will pass. - api From 49db26f432c93563c7a657f94d66590aa726cb2b Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 20:08:23 -0600 Subject: [PATCH 011/153] sphinx fix; README --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 9afb920..5748e01 100644 --- a/README.rst +++ b/README.rst @@ -24,17 +24,17 @@ This is easily achieved by downloading `the Adafruit library and driver bundle `_. Usage Example -============= +============== Hardware Set-up ---------------- +---------------- The DHT11 and DHT22 devices both need a pull-resistor on the data signal wire. This resistor is in the range of 1k to 5k. Please check your device datasheet for the appropriate value. Basics ------- +------- Of course, you must import the library to use it: @@ -61,7 +61,7 @@ OR initialize the DHT22 device: dht_device = adafruit_dht.DHT22() Read temperature and humidity ----------------------------- +------------------------------ Now get the temperature and humidity values From b5d59b39691bea5a147a5cd9e5c2fae0825270ba Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 24 Feb 2018 20:35:09 -0600 Subject: [PATCH 012/153] updated examples; requested change in PR #4 --- examples/dht_simpletest.py | 2 +- examples/dht_to_led_display.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index 1947174..ef2e81c 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -8,7 +8,7 @@ while True: try: # show the values to the serial port - temperature = dhtDevice.temperature*9/5+32 + temperature = dhtDevice.temperature * (9 / 5) + 32 humidity = dhtDevice.humidity print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index b3b7335..de7bed1 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -25,7 +25,7 @@ while True: try: # show the values to the serial port - temperature = dhtDevice.temperature*9/5+32 + temperature = dhtDevice.temperature * (9 / 5) + 32 humidity = dhtDevice.humidity #print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) From cffe9190f63b70b89311a2ad2f8b959736a48d7d Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 10 Mar 2018 09:40:33 -0600 Subject: [PATCH 013/153] updated README; added Travis badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index 5748e01..36e310f 100644 --- a/README.rst +++ b/README.rst @@ -11,6 +11,10 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord +.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_DHT.svg?branch=master + :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_DHT + :alt: Build Status + CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. Dependencies From 5794b1cae96e248cfbc383452939849df98e7832 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sat, 10 Mar 2018 09:40:49 -0600 Subject: [PATCH 014/153] updated conf.py; bus device intersphinx link --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index c853a13..4cfd5d3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -16,7 +16,7 @@ ] intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None), - 'BusDevice': ('https://circuitpython.readthedocs.io/projects/bus_device/en/latest/', None), + 'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None), 'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None), 'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} From 2531cb06ee2009bd95b9810f6a61464c08349655 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 16 Mar 2018 18:28:24 -0500 Subject: [PATCH 015/153] added LICENSE file --- LICENSE | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..75d7f43 --- /dev/null +++ b/LICENSE @@ -0,0 +1,20 @@ +The MIT License (MIT) + +Copyright (c) 2017 Mike McWethy for Adafruit Industries +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 354dbf94f9467a56e9038df8fb0ebb62d6402c02 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 16 Apr 2018 08:01:32 -0400 Subject: [PATCH 016/153] modifued get_pulses to reduce errors - wait for timeout then use last 81 pulses - adjust lockout for dht11 --- adafruit_dht.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index f455fe6..d15e6d9 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -100,7 +100,6 @@ def _get_pulses(self): pulses will have 81 elements for the DHT11/22 type devices. """ pulses = array.array('H') - tmono = time.monotonic() # create the PulseIn object using context manager with pulseio.PulseIn(self._pin, 81, True) as pulse_in: @@ -115,13 +114,15 @@ def _get_pulses(self): pulse_in.resume(self._trig_wait) # loop until we get the return pulse we need or - # time out after 1/2 seconds + # time out after 1/4 second + tmono = time.monotonic() while True: - if len(pulse_in) >= 80: - break - if time.monotonic()-tmono > 0.5: # time out after 1/2 seconds + #if len(pulse_in) >= 82: + # break + if time.monotonic()-tmono > 0.25: # time out after 1/4 seconds break + #print(len(pulse_in)) pulse_in.pause() while pulse_in: pulses.append(pulse_in.popleft()) @@ -137,11 +138,15 @@ def measure(self): Raises RuntimeError exception for checksum failure and for insuffcient data returned from the device (try again) """ - if time.monotonic()-self._last_called > 0.5: + delay_between_readings = 0.5 + if(self._dht11): + delay_between_readings = 1.0 + if time.monotonic()-self._last_called > delay_between_readings: self._last_called = time.monotonic() pulses = self._get_pulses() - ##print(pulses) + #print(pulses) + #print(len(pulses)) if len(pulses) >= 80: buf = array.array('B') @@ -169,6 +174,7 @@ def measure(self): # checksum is the last byte if chk_sum & 0xff != buf[4]: # check sum failed to validate + #print(pulses) raise RuntimeError("Checksum did not validate. Try again.") #print("checksum did not match. Temp: {} Humidity: {} Checksum:{}" #.format(self._temperature,self._humidity,bites[4])) From 053e0f46218f3cc51103f43db429a31baca3a521 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 16 Apr 2018 09:28:50 -0400 Subject: [PATCH 017/153] pylint fix --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index d15e6d9..4c9b5b4 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -139,7 +139,7 @@ def measure(self): data returned from the device (try again) """ delay_between_readings = 0.5 - if(self._dht11): + if self._dht11 : delay_between_readings = 1.0 if time.monotonic()-self._last_called > delay_between_readings: self._last_called = time.monotonic() From 0cf82dc9e51c03c6930cc13556cf6a0f239e5322 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 16 Apr 2018 09:34:01 -0400 Subject: [PATCH 018/153] pylint fix --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 4c9b5b4..57c9d88 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -139,7 +139,7 @@ def measure(self): data returned from the device (try again) """ delay_between_readings = 0.5 - if self._dht11 : + if self._dht11: delay_between_readings = 1.0 if time.monotonic()-self._last_called > delay_between_readings: self._last_called = time.monotonic() From 45a7fb5dba817581cce777f482052c137e617818 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 16 Apr 2018 13:39:39 -0400 Subject: [PATCH 019/153] remove commented code --- adafruit_dht.py | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 57c9d88..068405f 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -117,12 +117,9 @@ def _get_pulses(self): # time out after 1/4 second tmono = time.monotonic() while True: - #if len(pulse_in) >= 82: - # break if time.monotonic()-tmono > 0.25: # time out after 1/4 seconds break - #print(len(pulse_in)) pulse_in.pause() while pulse_in: pulses.append(pulse_in.popleft()) @@ -145,14 +142,11 @@ def measure(self): self._last_called = time.monotonic() pulses = self._get_pulses() - #print(pulses) - #print(len(pulses)) if len(pulses) >= 80: buf = array.array('B') for byte_start in range(0, 80, 16): buf.append(self._pulses_to_binary(pulses, byte_start, byte_start+16)) - #print(buf) # humidity is 2 bytes if self._dht11: @@ -160,7 +154,7 @@ def measure(self): else: self._humidity = ((buf[0]<<8) | buf[1]) / 10 - # tempature is 2 bytes + # temperature is 2 bytes if self._dht11: self._temperature = buf[2] else: @@ -174,17 +168,11 @@ def measure(self): # checksum is the last byte if chk_sum & 0xff != buf[4]: # check sum failed to validate - #print(pulses) raise RuntimeError("Checksum did not validate. Try again.") - #print("checksum did not match. Temp: {} Humidity: {} Checksum:{}" - #.format(self._temperature,self._humidity,bites[4])) - # checksum matches - #print("Temp: {} C Humidity: {}% ".format(self._temperature, self._humidity)) else: raise RuntimeError("A full buffer was not returned. Try again.") - #print("did not get a full return. number returned was: {}".format(len(r))) @property def temperature(self): From 2046e8efc00369bf3ae3420bbcc2a540dca31bdb Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sat, 28 Apr 2018 16:14:34 -0400 Subject: [PATCH 020/153] fix DHT22 handling of negative temperatures --- adafruit_dht.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 068405f..b4d8da8 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -148,17 +148,23 @@ def measure(self): for byte_start in range(0, 80, 16): buf.append(self._pulses_to_binary(pulses, byte_start, byte_start+16)) - # humidity is 2 bytes if self._dht11: + # humidity is 1 byte self._humidity = buf[0] else: + # humidity is 2 bytes self._humidity = ((buf[0]<<8) | buf[1]) / 10 - # temperature is 2 bytes if self._dht11: + # temperature is 1 byte self._temperature = buf[2] else: - self._temperature = ((buf[2]<<8) | buf[3]) / 10 + # temperature is 2 bytes + # MSB ist sign, bits 0-14 are magnitude) + self._temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 + # set sign + if buf[2] & 0x80: + self._temperature = -self.temperature # calc checksum chk_sum = 0 From c8dbbdb7790693791c72a420e992c0306625fb27 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sat, 28 Apr 2018 16:25:49 -0400 Subject: [PATCH 021/153] fix typo --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index b4d8da8..9ed07b4 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -164,7 +164,7 @@ def measure(self): self._temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 # set sign if buf[2] & 0x80: - self._temperature = -self.temperature + self._temperature = -self._temperature # calc checksum chk_sum = 0 From 2aaaf1b340abbe5562ed1a11947dcf418534a1eb Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sat, 28 Apr 2018 17:03:15 -0400 Subject: [PATCH 022/153] fix pylint issue --- adafruit_dht.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 9ed07b4..e7e8595 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -160,12 +160,12 @@ def measure(self): self._temperature = buf[2] else: # temperature is 2 bytes - # MSB ist sign, bits 0-14 are magnitude) - self._temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 + # MSB is sign, bits 0-14 are magnitude) + raw_temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 # set sign if buf[2] & 0x80: - self._temperature = -self._temperature - + raw_temperature = -raw_temperature + self._temperature = raw_temperature # calc checksum chk_sum = 0 for b in buf[0:4]: @@ -176,7 +176,6 @@ def measure(self): # check sum failed to validate raise RuntimeError("Checksum did not validate. Try again.") - else: raise RuntimeError("A full buffer was not returned. Try again.") From eaa625d6238558ab662cb87ba73d9a5a49418e92 Mon Sep 17 00:00:00 2001 From: Brennen Bearnes Date: Thu, 26 Jul 2018 23:56:25 -0600 Subject: [PATCH 023/153] add setup.py & better .gitignore, misc. tweaks for pypi Per instructions at: adafruit/circuitpython#979 --- .gitignore | 10 +++++++- .travis.yml | 34 +++++++++++++-------------- docs/conf.py | 2 -- requirements.txt | 1 + setup.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 86 insertions(+), 21 deletions(-) create mode 100644 setup.py diff --git a/.gitignore b/.gitignore index 5b5b0c8..cc1a9c8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,12 @@ +*.mpy +.idea +__pycache__ +_build +*.pyc .env build* bundles - +*.DS_Store +.eggs +dist +**/*.egg-info diff --git a/.travis.yml b/.travis.yml index 36ca9b5..523a40c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,31 +1,29 @@ -# This is a common .travis.yml for generating library release zip files for -# CircuitPython library releases using circuitpython-build-tools. -# See https://github.com/adafruit/circuitpython-build-tools for detailed setup -# instructions. - dist: trusty sudo: false language: python python: - - "3.6" - +- '3.6' cache: - pip: true - + pip: true deploy: provider: releases - api_key: $GITHUB_TOKEN + api_key: "$GITHUB_TOKEN" file_glob: true - file: $TRAVIS_BUILD_DIR/bundles/* + file: "$TRAVIS_BUILD_DIR/bundles/*" skip_cleanup: true on: tags: true - +- provider: pypi + user: adafruit-travis + on: + tags: true + password: + secure: vygpUo9Cn8Jn2LqKP1MXzhlusmEoJLB/OBRbni7sI6V0STk04D6/8y3tCvqxhllhCz9CeGTygW8F97TmsgzjXo/jinEbb2wKpCUUa1m6JuJK3tgvg/VaR3OdTFzkbcphP9W00mQs1tjA3L5Kpnj3J3G8X3/Bmq8JKxbMygCyUfCYqNzxv8DptUye/XCG1vMBrJD+Pd+aSgw/OlWmc8rHrg19p8+boVSouOgI/fVFSGCc78iDly6Uzk0nlDtBwh2XH/2AhhgoxLGQZbwblFzJ/kV/NdVdp9BWD1xsY7+2Pi/yN7/7Xk+/ffpYKnGxA6gRcIbjAd6QJxmmJySnz4INABjSiohs1iI5zhqjiQeGevsmGQJx/mcNxExie+DVtjWjkbwEB/ayWDiLrphtVrN2hFzBznlkEPNp+eVECRe1bUnsRJf5rzLs/4VRP+XN4pYjXBFo8Dd/QpjiB8rC579c3IS/frdamC0Za1muHmWw4mXzhCt1gGJznewGBraFM7YRIk/5LeRgJxbLih66glmppHYnoDUkMd7jzcw46OMzmTzJGTXk17mHA/bTKaCUQYjBLOQ9PizJq3nZxan08A7cXOcepNrpodyorpn4sDujYbv3LyLCxe1nswjGknoTDojb+sFO6Yq/LnZyitx6uwv5Lkj3U0qvOj8DQLtkyKS6xIo= install: - - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme - +- pip install -r requirements.txt +- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme script: - - pylint adafruit_dht.py - - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . - - cd docs && sphinx-build -E -W -b html . _build/html +- pylint adafruit_dht.py +- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) +- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . +- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/docs/conf.py b/docs/conf.py index 4cfd5d3..92f399d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -20,8 +20,6 @@ 'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None), 'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} -autodoc_mock_imports = ["pulseio"] - # Add any paths that contain templates here, relative to this directory. templates_path = ['_templates'] diff --git a/requirements.txt b/requirements.txt index e69de29..edf9394 100644 --- a/requirements.txt +++ b/requirements.txt @@ -0,0 +1 @@ +Adafruit-Blinka diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2817391 --- /dev/null +++ b/setup.py @@ -0,0 +1,60 @@ +"""A setuptools based setup module. + +See: +https://packaging.python.org/en/latest/distributing.html +https://github.com/pypa/sampleproject +""" + +# Always prefer setuptools over distutils +from setuptools import setup, find_packages +# To use a consistent encoding +from codecs import open +from os import path + +here = path.abspath(path.dirname(__file__)) + +# Get the long description from the README file +with open(path.join(here, 'README.rst'), encoding='utf-8') as f: + long_description = f.read() + +setup( + name='adafruit-circuitpython-dht', + + use_scm_version=True, + setup_requires=['setuptools_scm'], + + description='CircuitPython support for DHT11 and DHT22 type temperature/humidity devices', + long_description=long_description, + long_description_content_type='text/x-rst', + + # The project's main homepage. + url='https://github.com/adafruit/Adafruit_CircuitPython_DHT', + + # Author details + author='Adafruit Industries', + author_email='circuitpython@adafruit.com', + + install_requires=['Adafruit-Blinka'], + + # Choose your license + license='MIT', + + # See https://pypi.python.org/pypi?%3Aaction=list_classifiers + classifiers=[ + 'Development Status :: 3 - Alpha', + 'Intended Audience :: Developers', + 'Topic :: Software Development :: Libraries', + 'Topic :: System :: Hardware', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.4', + 'Programming Language :: Python :: 3.5', + ], + + # What does your project relate to? + keywords='adafruit dht hardware sensors temperature humidity micropython circuitpython', + + # You can just specify the packages manually here if your project is + # simple. Or you can use find_packages(). + py_modules=['adafruit_dht'], +) From ef73b96de873f102c2afced4d44e86fe3d2fa0ef Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 3 Aug 2018 12:39:15 -0400 Subject: [PATCH 024/153] Updates for PyPi, linting. --- .travis.yml | 4 +++- docs/conf.py | 2 ++ examples/dht_simpletest.py | 2 +- examples/dht_to_led_display.py | 6 +++--- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 523a40c..a64ee26 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,12 @@ python: cache: pip: true deploy: - provider: releases +- provider: releases api_key: "$GITHUB_TOKEN" file_glob: true file: "$TRAVIS_BUILD_DIR/bundles/*" skip_cleanup: true + overwrite: true on: tags: true - provider: pypi @@ -22,6 +23,7 @@ deploy: install: - pip install -r requirements.txt - pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme +- pip install --force-reinstall pylint==1.9.2 script: - pylint adafruit_dht.py - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) diff --git a/docs/conf.py b/docs/conf.py index 92f399d..caed051 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -15,6 +15,8 @@ 'sphinx.ext.viewcode', ] +autodoc_mock_imports = ["pulseio"] + intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None), 'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None), 'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None), diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index ef2e81c..4686c4d 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -1,6 +1,6 @@ import time -import adafruit_dht from board import D2 +import adafruit_dht #initial the dht device dhtDevice = adafruit_dht.DHT22(D2) diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index de7bed1..7eee861 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -5,16 +5,16 @@ """ # import for dht devices and 7-segment display devices import time +from board import D2, TX, RX, D1 import adafruit_dht -from adafruit_max7219 import bcddigits +from adafruit_max7219 import bcddigits import busio import digitalio -from board import D2, TX, RX, A2 clk = RX din = TX -cs = digitalio.DigitalInOut(A2) +cs = digitalio.DigitalInOut(D1) spi = busio.SPI(clk, MOSI=din) display = bcddigits.BCDDigits(spi, cs, nDigits=8) display.brightness(5) From bd8aa8e65e855ac00212b259422742335b1ef632 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 3 Aug 2018 12:43:10 -0400 Subject: [PATCH 025/153] linting --- examples/dht_to_led_display.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index 7eee861..3286f3b 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -6,10 +6,10 @@ # import for dht devices and 7-segment display devices import time from board import D2, TX, RX, D1 -import adafruit_dht -from adafruit_max7219 import bcddigits import busio import digitalio +import adafruit_dht +from adafruit_max7219 import bcddigits clk = RX From 23254cab7e6586af369a578027f8142e7eba23dc Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 14 Aug 2018 20:01:03 -0500 Subject: [PATCH 026/153] ignore the board module imports in .pylintrc Signed-off-by: sommersoft --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index e274ba9..8154969 100644 --- a/.pylintrc +++ b/.pylintrc @@ -155,7 +155,7 @@ ignored-classes=optparse.Values,thread._local,_thread._local # (useful for modules/projects where namespaces are manipulated during runtime # and thus existing member attributes cannot be deduced by static analysis. It # supports qualified module names, as well as Unix pattern matching. -ignored-modules= +ignored-modules=board # Show a hint with possible names when a member name was not found. The aspect # of finding the hint is based on edit distance. From 93aed219d41d03755b4b7a1425b6798ea2f8f033 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 14 Oct 2018 13:39:04 -0400 Subject: [PATCH 027/153] fix first read issue --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index e7e8595..e7759a3 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,7 +138,7 @@ def measure(self): delay_between_readings = 0.5 if self._dht11: delay_between_readings = 1.0 - if time.monotonic()-self._last_called > delay_between_readings: + if (self._last_called == 0) or (time.monotonic()-self._last_called > delay_between_readings): self._last_called = time.monotonic() pulses = self._get_pulses() From 8d7ce76e7f3a30f3227b53527a8f43713fbd4b9f Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Sun, 14 Oct 2018 13:54:26 -0400 Subject: [PATCH 028/153] fix pylint issue - line too long --- adafruit_dht.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index e7759a3..490d13b 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,7 +138,8 @@ def measure(self): delay_between_readings = 0.5 if self._dht11: delay_between_readings = 1.0 - if (self._last_called == 0) or (time.monotonic()-self._last_called > delay_between_readings): + if (self._last_called == 0) or \ + (time.monotonic()-self._last_called > delay_between_readings): self._last_called = time.monotonic() pulses = self._get_pulses() From ddb9d66096b19eb8110cee303b1e3a223884ec78 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 15 Oct 2018 07:39:00 -0400 Subject: [PATCH 029/153] fix continuation line --- adafruit_dht.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 490d13b..2037c41 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,8 +138,8 @@ def measure(self): delay_between_readings = 0.5 if self._dht11: delay_between_readings = 1.0 - if (self._last_called == 0) or \ - (time.monotonic()-self._last_called > delay_between_readings): + if (self._last_called == 0 or + (time.monotonic()-self._last_called) > delay_between_readings): self._last_called = time.monotonic() pulses = self._get_pulses() From bcdc7a7469e936fb70e9c865ae0a2220b1fe7041 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Mon, 15 Oct 2018 07:50:31 -0400 Subject: [PATCH 030/153] fix continuation line - add comment --- adafruit_dht.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_dht.py b/adafruit_dht.py index 2037c41..1049c5e 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,6 +138,9 @@ def measure(self): delay_between_readings = 0.5 if self._dht11: delay_between_readings = 1.0 + # Initialte new reading if this is the first call or if sufficient delay + # If delay not sufficient - return previous reading. + # This allows back to back access for temperature and humidity for same reading if (self._last_called == 0 or (time.monotonic()-self._last_called) > delay_between_readings): self._last_called = time.monotonic() From 125890ed6e9b33a7a96f58ce3055c529c018b452 Mon Sep 17 00:00:00 2001 From: Scott Shawcroft Date: Tue, 16 Oct 2018 11:24:33 -0700 Subject: [PATCH 031/153] Fix typo --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 1049c5e..e4842c3 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,7 +138,7 @@ def measure(self): delay_between_readings = 0.5 if self._dht11: delay_between_readings = 1.0 - # Initialte new reading if this is the first call or if sufficient delay + # Initiate new reading if this is the first call or if sufficient delay # If delay not sufficient - return previous reading. # This allows back to back access for temperature and humidity for same reading if (self._last_called == 0 or From d4ec646fb2c3efa88f6ca152672bc4483b75b66c Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Wed, 17 Oct 2018 06:34:29 -0400 Subject: [PATCH 032/153] resolve pr_14 conflicts - fix bug with sample delay --- adafruit_dht.py | 91 ++++++++++++++++++++++------------ examples/dht_simpletest.py | 17 ++++--- examples/dht_to_led_display.py | 2 +- 3 files changed, 69 insertions(+), 41 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index e4842c3..edf679c 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -30,12 +30,14 @@ import array import time +from digitalio import DigitalInOut, Pull, Direction +_USE_PULSEIO = False try: import pulseio -except ImportError as excpt: - print("adafruit_dht requires the pulseio library, but it failed to load."+ - " Note that CircuitPython does not support pulseio on all boards.") - raise excpt + _USE_PULSEIO = True +except ImportError: + pass # This is OK, we'll try to bitbang it! + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git" @@ -101,30 +103,51 @@ def _get_pulses(self): """ pulses = array.array('H') - # create the PulseIn object using context manager - with pulseio.PulseIn(self._pin, 81, True) as pulse_in: - - # The DHT type device use a specialize 1-wire protocol - # The microprocessor first sends a LOW signal for a - # specific length of time. Then the device sends back a - # series HIGH and LOW signals. The length the HIGH signals - # represents the device values. - pulse_in.pause() - pulse_in.clear() - pulse_in.resume(self._trig_wait) - - # loop until we get the return pulse we need or - # time out after 1/4 second - tmono = time.monotonic() - while True: - if time.monotonic()-tmono > 0.25: # time out after 1/4 seconds - break - - pulse_in.pause() - while pulse_in: - pulses.append(pulse_in.popleft()) - pulse_in.resume() - + if _USE_PULSEIO: + # create the PulseIn object using context manager + with pulseio.PulseIn(self._pin, 81, True) as pulse_in: + + # The DHT type device use a specialize 1-wire protocol + # The microprocessor first sends a LOW signal for a + # specific length of time. Then the device sends back a + # series HIGH and LOW signals. The length the HIGH signals + # represents the device values. + pulse_in.pause() + pulse_in.clear() + pulse_in.resume(self._trig_wait) + + # loop until we get the return pulse we need or + # time out after 1/4 second + tmono = time.monotonic() + while time.monotonic() - tmono < 0.25: + pass # time out after 1/4 seconds + pulse_in.pause() + while pulse_in: + pulses.append(pulse_in.popleft()) + pulse_in.resume() + else: + with DigitalInOut(self._pin) as dhtpin: + # we will bitbang if no pulsein capability + transitions = [] + # Signal by setting pin high, then low, and releasing + dhtpin.direction = Direction.OUTPUT + dhtpin.value = True + time.sleep(0.1) + dhtpin.value = False + time.sleep(0.001) + + timestamp = time.monotonic() # take timestamp + dhtval = True # start with dht pin true because its pulled up + dhtpin.direction = Direction.INPUT + dhtpin.pull = Pull.UP + while time.monotonic() - timestamp < 0.1: + if dhtval != dhtpin.value: + dhtval = not dhtval # we toggled + transitions.append(time.monotonic()) # save the timestamp + # convert transtions to microsecond delta pulses: + for i in range(1, len(transitions)): + pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1])) + pulses.append(min(pulses_micro_sec, 65535)) return pulses def measure(self): @@ -135,9 +158,7 @@ def measure(self): Raises RuntimeError exception for checksum failure and for insuffcient data returned from the device (try again) """ - delay_between_readings = 0.5 - if self._dht11: - delay_between_readings = 1.0 + delay_between_readings = 2 # 2 seconds per read according to datasheet # Initiate new reading if this is the first call or if sufficient delay # If delay not sufficient - return previous reading. # This allows back to back access for temperature and humidity for same reading @@ -146,6 +167,7 @@ def measure(self): self._last_called = time.monotonic() pulses = self._get_pulses() + #print(len(pulses), "pulses:", [x for x in pulses]) if len(pulses) >= 80: buf = array.array('B') @@ -180,9 +202,12 @@ def measure(self): # check sum failed to validate raise RuntimeError("Checksum did not validate. Try again.") - else: + elif len(pulses) >= 10: + # We got *some* data just not 81 bits raise RuntimeError("A full buffer was not returned. Try again.") - + else: + # Probably a connection issue! + raise RuntimeError("DHT sensor not found, check wiring") @property def temperature(self): """ temperature current reading. It makes sure a reading is available diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index 4686c4d..e07c078 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -1,18 +1,21 @@ import time -from board import D2 +import board import adafruit_dht -#initial the dht device -dhtDevice = adafruit_dht.DHT22(D2) +# Initial the dht device, with data pin connected to: +dhtDevice = adafruit_dht.DHT22(board.D18) while True: try: - # show the values to the serial port - temperature = dhtDevice.temperature * (9 / 5) + 32 + # Print the values to the serial port + temperature_c = dhtDevice.temperature + temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity - print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) + print("Temp: {:.1f} F / {:.1f} C Humidity: {}% " + .format(temperature_f, temperature_c, humidity)) except RuntimeError as error: - print(error.args) + # Errors happen fairly often, DHT's are hard to read, just keep going + print(error.args[0]) time.sleep(2.0) diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index 3286f3b..d3cb3a9 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -35,6 +35,6 @@ display.show() except RuntimeError as error: - print(error.args) + print(error.args[0]) time.sleep(2.0) From de4f5f38f5fb25f89847f2e17c58b14519d1ec80 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Wed, 17 Oct 2018 06:40:08 -0400 Subject: [PATCH 033/153] pylint - indent error --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index edf679c..27e5e22 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -120,7 +120,7 @@ def _get_pulses(self): # time out after 1/4 second tmono = time.monotonic() while time.monotonic() - tmono < 0.25: - pass # time out after 1/4 seconds + pass # time out after 1/4 seconds pulse_in.pause() while pulse_in: pulses.append(pulse_in.popleft()) From d122696eda4a5e7858b23141ef67a556db4a5224 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Wed, 17 Oct 2018 07:36:43 -0400 Subject: [PATCH 034/153] tweak to RPi pulse detect --- adafruit_dht.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 27e5e22..5cd8748 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -145,7 +145,9 @@ def _get_pulses(self): dhtval = not dhtval # we toggled transitions.append(time.monotonic()) # save the timestamp # convert transtions to microsecond delta pulses: - for i in range(1, len(transitions)): + # use last 81 pulses + transition_start = max(1, len(transitions) - 81) + for i in range(transition_start, len(transitions)): pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1])) pulses.append(min(pulses_micro_sec, 65535)) return pulses From d2da8739c030a66c5d17e731ed9debe9409e5e37 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Wed, 17 Oct 2018 14:57:53 -0400 Subject: [PATCH 035/153] make delay for bitbang same as for pulseio --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 5cd8748..eebcdd6 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -140,7 +140,7 @@ def _get_pulses(self): dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT dhtpin.pull = Pull.UP - while time.monotonic() - timestamp < 0.1: + while time.monotonic() - timestamp < 0.25: if dhtval != dhtpin.value: dhtval = not dhtval # we toggled transitions.append(time.monotonic()) # save the timestamp From 105157930bfa10f0734f8ef308b11a8333583067 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Thu, 18 Oct 2018 22:07:09 -0400 Subject: [PATCH 036/153] create private functions for pulseio and bitbang version of getting pulses --- adafruit_dht.py | 115 +++++++++++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 54 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index eebcdd6..2860bee 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -91,7 +91,7 @@ def _pulses_to_binary(self, pulses, start, stop): return binary - def _get_pulses(self): + def _get_pulses_pulseio(self): """ _get_pulses implements the communication protcol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the @@ -102,54 +102,61 @@ def _get_pulses(self): pulses will have 81 elements for the DHT11/22 type devices. """ pulses = array.array('H') + # create the PulseIn object using context manager + with pulseio.PulseIn(self._pin, 81, True) as pulse_in: + # The DHT type device use a specialize 1-wire protocol + # The microprocessor first sends a LOW signal for a + # specific length of time. Then the device sends back a + # series HIGH and LOW signals. The length the HIGH signals + # represents the device values. + pulse_in.pause() + pulse_in.clear() + pulse_in.resume(self._trig_wait) + # loop until we get the return pulse we need or + # time out after 1/4 second + tmono = time.monotonic() + while time.monotonic() - tmono < 0.25: + pass # time out after 1/4 seconds + pulse_in.pause() + while pulse_in: + pulses.append(pulse_in.popleft()) + pulse_in.resume() + return pulses + + def _get_pulses_bitbang(self): + """ _get_pulses implements the communication protcol for + DHT11 and DHT22 type devices. It sends a start signal + of a specific length and listens and measures the + return signal lengths. - if _USE_PULSEIO: - # create the PulseIn object using context manager - with pulseio.PulseIn(self._pin, 81, True) as pulse_in: - - # The DHT type device use a specialize 1-wire protocol - # The microprocessor first sends a LOW signal for a - # specific length of time. Then the device sends back a - # series HIGH and LOW signals. The length the HIGH signals - # represents the device values. - pulse_in.pause() - pulse_in.clear() - pulse_in.resume(self._trig_wait) - - # loop until we get the return pulse we need or - # time out after 1/4 second - tmono = time.monotonic() - while time.monotonic() - tmono < 0.25: - pass # time out after 1/4 seconds - pulse_in.pause() - while pulse_in: - pulses.append(pulse_in.popleft()) - pulse_in.resume() - else: - with DigitalInOut(self._pin) as dhtpin: - # we will bitbang if no pulsein capability - transitions = [] - # Signal by setting pin high, then low, and releasing - dhtpin.direction = Direction.OUTPUT - dhtpin.value = True - time.sleep(0.1) - dhtpin.value = False - time.sleep(0.001) - - timestamp = time.monotonic() # take timestamp - dhtval = True # start with dht pin true because its pulled up - dhtpin.direction = Direction.INPUT - dhtpin.pull = Pull.UP - while time.monotonic() - timestamp < 0.25: - if dhtval != dhtpin.value: - dhtval = not dhtval # we toggled - transitions.append(time.monotonic()) # save the timestamp - # convert transtions to microsecond delta pulses: - # use last 81 pulses - transition_start = max(1, len(transitions) - 81) - for i in range(transition_start, len(transitions)): - pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1])) - pulses.append(min(pulses_micro_sec, 65535)) + return pulses (array.array uint16) contains alternating high and low + transition times starting with a low transition time. Normally + pulses will have 81 elements for the DHT11/22 type devices. + """ + pulses = array.array('H') + with DigitalInOut(self._pin) as dhtpin: + # we will bitbang if no pulsein capability + transitions = [] + # Signal by setting pin high, then low, and releasing + dhtpin.direction = Direction.OUTPUT + dhtpin.value = True + time.sleep(0.1) + dhtpin.value = False + time.sleep(0.001) + timestamp = time.monotonic() # take timestamp + dhtval = True # start with dht pin true because its pulled up + dhtpin.direction = Direction.INPUT + dhtpin.pull = Pull.UP + while time.monotonic() - timestamp < 0.25: + if dhtval != dhtpin.value: + dhtval = not dhtval # we toggled + transitions.append(time.monotonic()) # save the timestamp + # convert transtions to microsecond delta pulses: + # use last 81 pulses + transition_start = max(1, len(transitions) - 81) + for i in range(transition_start, len(transitions)): + pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1])) + pulses.append(min(pulses_micro_sec, 65535)) return pulses def measure(self): @@ -168,7 +175,10 @@ def measure(self): (time.monotonic()-self._last_called) > delay_between_readings): self._last_called = time.monotonic() - pulses = self._get_pulses() + if _USE_PULSEIO: + pulses = self._get_pulses_pulseio() + else: + pulses = self._get_pulses_bitbang() #print(len(pulses), "pulses:", [x for x in pulses]) if len(pulses) >= 80: @@ -179,14 +189,11 @@ def measure(self): if self._dht11: # humidity is 1 byte self._humidity = buf[0] - else: - # humidity is 2 bytes - self._humidity = ((buf[0]<<8) | buf[1]) / 10 - - if self._dht11: # temperature is 1 byte self._temperature = buf[2] else: + # humidity is 2 bytes + self._humidity = ((buf[0]<<8) | buf[1]) / 10 # temperature is 2 bytes # MSB is sign, bits 0-14 are magnitude) raw_temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 From 98fcb2b71913412cea7377977e894c341e597de5 Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 1 Dec 2018 02:06:56 -0500 Subject: [PATCH 037/153] removed context for pulse_in to make linux happy, and change delay to not use time.monotonic --- adafruit_dht.py | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 2860bee..316fad6 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -60,7 +60,10 @@ def __init__(self, dht11, pin, trig_wait): self._last_called = 0 self._humidity = None self._temperature = None - + # We don't use a context because linux-based systems are sluggish + # and we're better off having a running process + if _USE_PULSEIO: + self.pulse_in = pulseio.PulseIn(self._pin, 81, True) def _pulses_to_binary(self, pulses, start, stop): """Takes pulses, a list of transition times, and converts @@ -102,25 +105,22 @@ def _get_pulses_pulseio(self): pulses will have 81 elements for the DHT11/22 type devices. """ pulses = array.array('H') - # create the PulseIn object using context manager - with pulseio.PulseIn(self._pin, 81, True) as pulse_in: - # The DHT type device use a specialize 1-wire protocol - # The microprocessor first sends a LOW signal for a - # specific length of time. Then the device sends back a - # series HIGH and LOW signals. The length the HIGH signals - # represents the device values. - pulse_in.pause() - pulse_in.clear() - pulse_in.resume(self._trig_wait) - # loop until we get the return pulse we need or - # time out after 1/4 second - tmono = time.monotonic() - while time.monotonic() - tmono < 0.25: - pass # time out after 1/4 seconds - pulse_in.pause() - while pulse_in: - pulses.append(pulse_in.popleft()) - pulse_in.resume() + if _USE_PULSEIO: + # The DHT type device use a specialize 1-wire protocol + # The microprocessor first sends a LOW signal for a + # specific length of time. Then the device sends back a + # series HIGH and LOW signals. The length the HIGH signals + # represents the device values. + self.pulse_in.pause() + self.pulse_in.clear() + self.pulse_in.resume(self._trig_wait) + + # loop until we get the return pulse we need or + # time out after 1/4 second + time.sleep(0.25) + self.pulse_in.pause() + while self.pulse_in: + pulses.append(self.pulse_in.popleft()) return pulses def _get_pulses_bitbang(self): From 90149ac09074621cddb7575079e4f363fd444e6f Mon Sep 17 00:00:00 2001 From: ladyada Date: Sat, 1 Dec 2018 02:08:04 -0500 Subject: [PATCH 038/153] nicetabs --- adafruit_dht.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 316fad6..017f9f2 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -106,21 +106,21 @@ def _get_pulses_pulseio(self): """ pulses = array.array('H') if _USE_PULSEIO: - # The DHT type device use a specialize 1-wire protocol - # The microprocessor first sends a LOW signal for a - # specific length of time. Then the device sends back a - # series HIGH and LOW signals. The length the HIGH signals - # represents the device values. - self.pulse_in.pause() - self.pulse_in.clear() - self.pulse_in.resume(self._trig_wait) - - # loop until we get the return pulse we need or - # time out after 1/4 second - time.sleep(0.25) - self.pulse_in.pause() - while self.pulse_in: - pulses.append(self.pulse_in.popleft()) + # The DHT type device use a specialize 1-wire protocol + # The microprocessor first sends a LOW signal for a + # specific length of time. Then the device sends back a + # series HIGH and LOW signals. The length the HIGH signals + # represents the device values. + self.pulse_in.pause() + self.pulse_in.clear() + self.pulse_in.resume(self._trig_wait) + + # loop until we get the return pulse we need or + # time out after 1/4 second + time.sleep(0.25) + self.pulse_in.pause() + while self.pulse_in: + pulses.append(self.pulse_in.popleft()) return pulses def _get_pulses_bitbang(self): From 62bb5c86d8ad7cbbce40fc73e4cbd631c3cd94cd Mon Sep 17 00:00:00 2001 From: sommersoft Date: Fri, 21 Dec 2018 13:25:35 -0600 Subject: [PATCH 039/153] change 'travis-ci.org' to 'travis-ci.com' --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 36e310f..0eb7276 100644 --- a/README.rst +++ b/README.rst @@ -11,8 +11,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.org/adafruit/Adafruit_CircuitPython_DHT.svg?branch=master - :target: https://travis-ci.org/adafruit/Adafruit_CircuitPython_DHT +.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_DHT.svg?branch=master + :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_DHT :alt: Build Status CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. From 0643ebbbcd8bdb4e233741511896069f29e1a917 Mon Sep 17 00:00:00 2001 From: Melissa LeBlanc-Williams Date: Wed, 11 Sep 2019 14:09:45 -0700 Subject: [PATCH 040/153] Lack of PulseIn detection now working --- adafruit_dht.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 017f9f2..2956cc7 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -33,7 +33,7 @@ from digitalio import DigitalInOut, Pull, Direction _USE_PULSEIO = False try: - import pulseio + from pulseio import PulseIn _USE_PULSEIO = True except ImportError: pass # This is OK, we'll try to bitbang it! @@ -63,7 +63,7 @@ def __init__(self, dht11, pin, trig_wait): # We don't use a context because linux-based systems are sluggish # and we're better off having a running process if _USE_PULSEIO: - self.pulse_in = pulseio.PulseIn(self._pin, 81, True) + self.pulse_in = PulseIn(self._pin, 81, True) def _pulses_to_binary(self, pulses, start, stop): """Takes pulses, a list of transition times, and converts From 097531b8fff209420e1951453aabe5bf4cd5e434 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Fri, 18 Oct 2019 10:55:46 -0400 Subject: [PATCH 041/153] Added PyPi installation instructions & documentation section --- README.rst | 74 +++++++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 46 deletions(-) diff --git a/README.rst b/README.rst index 0eb7276..64b8eba 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,31 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. +Installing from PyPI +==================== + +On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from +PyPI `_. To install for current user: + +.. code-block:: shell + + pip3 install adafruit-circuitpython-dht + +To install system-wide (this may be required in some cases): + +.. code-block:: shell + + sudo pip3 install adafruit-circuitpython-dht + +To install in a virtual environment in your current project: + +.. code-block:: shell + + mkdir project-name && cd project-name + python3 -m venv .env + source .env/bin/activate + pip3 install adafruit-circuitpython-dht + Usage Example ============== @@ -84,50 +109,7 @@ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. -Building locally -================ - -To build this library locally you'll need to install the -`circuitpython-build-tools `_ package. - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install circuitpython-build-tools - -Once installed, make sure you are in the virtual environment: - -.. code-block:: shell - - source .env/bin/activate - -Then run the build: - -.. code-block:: shell - - circuitpython-build-bundles --filename_prefix adafruit-circuitpython-veml6070 --library_location . - -Sphinx documentation ------------------------ - -Sphinx is used to build the documentation based on rST files and comments in the code. First, -install dependencies (feel free to reuse the virtual environment from above): - -.. code-block:: shell - - python3 -m venv .env - source .env/bin/activate - pip install Sphinx sphinx-rtd-theme - -Now, once you have the virtual environment activated: - -.. code-block:: shell - - cd docs - sphinx-build -E -W -b html . _build/html - -This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to -view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to -locally verify it will pass. +Documentation +============= +For information on building library documentation, please check out `this guide `_. From 3248e3e7919a811d6909a6f3d57b885bd57862b5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Sat, 4 Jan 2020 15:14:45 -0500 Subject: [PATCH 042/153] Moved repository from Travis to GitHub Actions --- .github/workflows/build.yml | 50 +++++++++++++++++++++ .github/workflows/release.yml | 81 +++++++++++++++++++++++++++++++++++ .gitignore | 1 - .travis.yml | 31 -------------- README.rst | 4 +- 5 files changed, 133 insertions(+), 34 deletions(-) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..66ce4db --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,50 @@ +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Library version + run: git describe --dirty --always --tags + - name: PyLint + run: | + pylint $( find . -path './adafruit*.py' ) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Build docs + working-directory: docs + run: sphinx-build -E -W -b html . _build/html diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..18efb9c --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,81 @@ +name: Release Actions + +on: + release: + types: [published] + +jobs: + upload-release-assets: + runs-on: ubuntu-latest + steps: + - name: Dump GitHub context + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: echo "$GITHUB_CONTEXT" + - name: Translate Repo Name For Build Tools filename_prefix + id: repo-name + run: | + echo ::set-output name=repo-name::$( + echo ${{ github.repository }} | + awk -F '\/' '{ print tolower($2) }' | + tr '_' '-' + ) + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + - name: Versions + run: | + python3 --version + - name: Checkout Current Repo + uses: actions/checkout@v1 + with: + submodules: true + - name: Checkout tools repo + uses: actions/checkout@v2 + with: + repository: adafruit/actions-ci-circuitpython-libs + path: actions-ci + - name: Install deps + run: | + source actions-ci/install.sh + - name: Build assets + run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Upload Release Assets + # the 'official' actions version does not yet support dynamically + # supplying asset names to upload. @csexton's version chosen based on + # discussion in the issue below, as its the simplest to implement and + # allows for selecting files with a pattern. + # https://github.com/actions/upload-release-asset/issues/4 + #uses: actions/upload-release-asset@v1.0.1 + uses: csexton/release-asset-action@master + with: + pattern: "bundles/*" + github-token: ${{ secrets.GITHUB_TOKEN }} + + upload-pypi: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Set up Python + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + uses: actions/setup-python@v1 + with: + python-version: '3.x' + - name: Install dependencies + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + python -m pip install --upgrade pip + pip install setuptools wheel twine + - name: Build and publish + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + env: + TWINE_USERNAME: ${{ secrets.pypi_username }} + TWINE_PASSWORD: ${{ secrets.pypi_password }} + run: | + python setup.py sdist + twine upload dist/* diff --git a/.gitignore b/.gitignore index cc1a9c8..1be1c4b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ __pycache__ _build *.pyc .env -build* bundles *.DS_Store .eggs diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index a64ee26..0000000 --- a/.travis.yml +++ /dev/null @@ -1,31 +0,0 @@ -dist: trusty -sudo: false -language: python -python: -- '3.6' -cache: - pip: true -deploy: -- provider: releases - api_key: "$GITHUB_TOKEN" - file_glob: true - file: "$TRAVIS_BUILD_DIR/bundles/*" - skip_cleanup: true - overwrite: true - on: - tags: true -- provider: pypi - user: adafruit-travis - on: - tags: true - password: - secure: vygpUo9Cn8Jn2LqKP1MXzhlusmEoJLB/OBRbni7sI6V0STk04D6/8y3tCvqxhllhCz9CeGTygW8F97TmsgzjXo/jinEbb2wKpCUUa1m6JuJK3tgvg/VaR3OdTFzkbcphP9W00mQs1tjA3L5Kpnj3J3G8X3/Bmq8JKxbMygCyUfCYqNzxv8DptUye/XCG1vMBrJD+Pd+aSgw/OlWmc8rHrg19p8+boVSouOgI/fVFSGCc78iDly6Uzk0nlDtBwh2XH/2AhhgoxLGQZbwblFzJ/kV/NdVdp9BWD1xsY7+2Pi/yN7/7Xk+/ffpYKnGxA6gRcIbjAd6QJxmmJySnz4INABjSiohs1iI5zhqjiQeGevsmGQJx/mcNxExie+DVtjWjkbwEB/ayWDiLrphtVrN2hFzBznlkEPNp+eVECRe1bUnsRJf5rzLs/4VRP+XN4pYjXBFo8Dd/QpjiB8rC579c3IS/frdamC0Za1muHmWw4mXzhCt1gGJznewGBraFM7YRIk/5LeRgJxbLih66glmppHYnoDUkMd7jzcw46OMzmTzJGTXk17mHA/bTKaCUQYjBLOQ9PizJq3nZxan08A7cXOcepNrpodyorpn4sDujYbv3LyLCxe1nswjGknoTDojb+sFO6Yq/LnZyitx6uwv5Lkj3U0qvOj8DQLtkyKS6xIo= -install: -- pip install -r requirements.txt -- pip install pylint circuitpython-build-tools Sphinx sphinx-rtd-theme -- pip install --force-reinstall pylint==1.9.2 -script: -- pylint adafruit_dht.py -- ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name examples/*.py) -- circuitpython-build-bundles --filename_prefix adafruit-circuitpython-dht --library_location . -- cd docs && sphinx-build -E -W -b html . _build/html && cd .. diff --git a/README.rst b/README.rst index 64b8eba..b7956c2 100644 --- a/README.rst +++ b/README.rst @@ -11,8 +11,8 @@ Introduction :target: https://discord.gg/nBQh6qu :alt: Discord -.. image:: https://travis-ci.com/adafruit/Adafruit_CircuitPython_DHT.svg?branch=master - :target: https://travis-ci.com/adafruit/Adafruit_CircuitPython_DHT +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_DHT/workflows/Build%20CI/badge.svg + :target: https://github.com/adafruit/Adafruit_CircuitPython_DHT/actions :alt: Build Status CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. From 0ea15b6a9f075ebecabc02f59dcff9cbcc6f3703 Mon Sep 17 00:00:00 2001 From: dherrada <33632497+dherrada@users.noreply.github.com> Date: Thu, 23 Jan 2020 10:51:32 -0500 Subject: [PATCH 043/153] Update pylint examples directive --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 66ce4db..11ce574 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,7 +42,7 @@ jobs: - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace examples/*.py) + ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Build docs From 7060d64d83b53713c35cc69e22de35bcfd359570 Mon Sep 17 00:00:00 2001 From: stefan Date: Fri, 28 Feb 2020 19:40:24 +0100 Subject: [PATCH 044/153] #34 update readme --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b7956c2..bdafd17 100644 --- a/README.rst +++ b/README.rst @@ -100,7 +100,8 @@ Now get the temperature and humidity values humidity = dht_device.humidity These properties may raise an exception if a problem occurs. You should use try/raise -logic and catch RuntimeError and then retry getting the values after 1/2 second. +logic and catch RuntimeError and then retry getting the values after at least 2 seconds. +If you try again to get a result within 2 seconds, cached values are returned. Contributing ============ From c23e7401f1840a1d402964e2113b85d56c220c30 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Sun, 15 Mar 2020 23:31:42 -0500 Subject: [PATCH 045/153] update code of conduct --- CODE_OF_CONDUCT.md | 125 ++++++++++++++++++++++++++++++++------------- 1 file changed, 90 insertions(+), 35 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 1617586..134d510 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,74 +1,129 @@ -# Contributor Covenant Code of Conduct +# Adafruit Community Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as -contributors and maintainers pledge to making participation in our project and +contributors and leaders pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body -size, disability, ethnicity, gender identity and expression, level of experience, -nationality, personal appearance, race, religion, or sexual identity and -orientation. +size, disability, ethnicity, gender identity and expression, level or type of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. ## Our Standards +We are committed to providing a friendly, safe and welcoming environment for +all. + Examples of behavior that contributes to creating a positive environment include: +* Be kind and courteous to others * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences +* Collaborating with other community members * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: -* The use of sexualized language or imagery and unwelcome sexual attention or -advances +* The use of sexualized language or imagery and sexual attention or advances +* The use of inappropriate images, including in a community member's avatar +* The use of inappropriate language, including in a community member's nickname +* Any spamming, flaming, baiting or other attention-stealing behavior +* Excessive or unwelcome helping; answering outside the scope of the question + asked * Trolling, insulting/derogatory comments, and personal or political attacks +* Promoting or spreading disinformation, lies, or conspiracy theories against + a person, group, organisation, project, or community * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission -* Other conduct which could reasonably be considered inappropriate in a - professional setting +* Other conduct which could reasonably be considered inappropriate + +The goal of the standards and moderation guidelines outlined here is to build +and maintain a respectful community. We ask that you don’t just aim to be +"technically unimpeachable", but rather try to be your best self. + +We value many things beyond technical expertise, including collaboration and +supporting others within our community. Providing a positive experience for +other community members can have a much more significant impact than simply +providing the correct answer. ## Our Responsibilities -Project maintainers are responsible for clarifying the standards of acceptable +Project leaders are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. -Project maintainers have the right and responsibility to remove, edit, or -reject comments, commits, code, wiki edits, issues, and other contributions +Project leaders have the right and responsibility to remove, edit, or +reject messages, comments, commits, code, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or -permanently any contributor for other behaviors that they deem inappropriate, -threatening, offensive, or harmful. +permanently any community member for other behaviors that they deem +inappropriate, threatening, offensive, or harmful. -## Scope +## Moderation -This Code of Conduct applies both within project spaces and in public spaces -when an individual is representing the project or its community. Examples of -representing a project or community include using an official project e-mail -address, posting via an official social media account, or acting as an appointed -representative at an online or offline event. Representation of a project may be -further defined and clarified by project maintainers. +Instances of behaviors that violate the Adafruit Community Code of Conduct +may be reported by any member of the community. Community members are +encouraged to report these situations, including situations they witness +involving other community members. + +You may report in the following ways: + +In any situation, you may send an email to . -## Enforcement +On the Adafruit Discord, you may send an open message from any channel +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +@sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported by contacting the project team at support@adafruit.com. All -complaints will be reviewed and investigated and will result in a response that -is deemed necessary and appropriate to the circumstances. The project team is -obligated to maintain confidentiality with regard to the reporter of an incident. -Further details of specific enforcement policies may be posted separately. +Email and direct message reports will be kept confidential. -Project maintainers who do not follow or enforce the Code of Conduct in good -faith may face temporary or permanent repercussions as determined by other -members of the project's leadership. +In situations on Discord where the issue is particularly egregious, possibly +illegal, requires immediate action, or violates the Discord terms of service, +you should also report the message directly to Discord. + +These are the steps for upholding our community’s standards of conduct. + +1. Any member of the community may report any situation that violates the +Adafruit Community Code of Conduct. All reports will be reviewed and +investigated. +2. If the behavior is an egregious violation, the community member who +committed the violation may be banned immediately, without warning. +3. Otherwise, moderators will first respond to such behavior with a warning. +4. Moderators follow a soft "three strikes" policy - the community member may +be given another chance, if they are receptive to the warning and change their +behavior. +5. If the community member is unreceptive or unreasonable when warned by a +moderator, or the warning goes unheeded, they may be banned for a first or +second offense. Repeated offenses will result in the community member being +banned. + +## Scope + +This Code of Conduct and the enforcement policies listed above apply to all +Adafruit Community venues. This includes but is not limited to any community +spaces (both public and private), the entire Adafruit Discord server, and +Adafruit GitHub repositories. Examples of Adafruit Community spaces include +but are not limited to meet-ups, audio chats on the Adafruit Discord, or +interaction at a conference. + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. As a community +member, you are representing our community, and are expected to behave +accordingly. ## Attribution -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, -available at [http://contributor-covenant.org/version/1/4][version] +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 1.4, available at +, +and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html). -[homepage]: http://contributor-covenant.org -[version]: http://contributor-covenant.org/version/1/4/ +For other projects adopting the Adafruit Community Code of +Conduct, please contact the maintainers of those projects for enforcement. +If you wish to use this code of conduct for your own project, consider +explicitly mentioning your moderation policy or making a copy with your +own moderation policy so as to avoid confusion. From b9ef1b5bfff41e2e4456e20fac9404e0847046cd Mon Sep 17 00:00:00 2001 From: sommersoft Date: Thu, 5 Mar 2020 22:06:59 -0600 Subject: [PATCH 046/153] update pylintrc for black Signed-off-by: sommersoft --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 8154969..5a43a10 100644 --- a/.pylintrc +++ b/.pylintrc @@ -52,7 +52,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From cd063e5094eb628a71d61ba36aba5abc18af927a Mon Sep 17 00:00:00 2001 From: sommersoft Date: Mon, 16 Mar 2020 21:12:48 -0500 Subject: [PATCH 047/153] update build.yml to pip install pylint black sphinx Signed-off-by: sommersoft --- .github/workflows/build.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 11ce574..fff3aa9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -34,9 +34,13 @@ jobs: with: repository: adafruit/actions-ci-circuitpython-libs path: actions-ci - - name: Install deps + - name: Install dependencies + # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh + - name: Pip install pylint, black, & Sphinx + run: | + pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint From 01c7d786e36e30dca88479afe81a9df5ca94d6ee Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 20 Mar 2020 12:13:58 -0400 Subject: [PATCH 048/153] Ran black, updated to pylint 2.x --- .github/workflows/build.yml | 2 +- adafruit_dht.py | 43 +++++++----- docs/conf.py | 121 ++++++++++++++++++++------------- examples/dht_simpletest.py | 7 +- examples/dht_to_led_display.py | 6 +- setup.py | 50 ++++++-------- 6 files changed, 129 insertions(+), 100 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index fff3aa9..1dad804 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,7 +40,7 @@ jobs: source actions-ci/install.sh - name: Pip install pylint, black, & Sphinx run: | - pip install --force-reinstall pylint==1.9.2 black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags - name: PyLint diff --git a/adafruit_dht.py b/adafruit_dht.py index 2956cc7..4c9083f 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -31,17 +31,20 @@ import array import time from digitalio import DigitalInOut, Pull, Direction + _USE_PULSEIO = False try: from pulseio import PulseIn + _USE_PULSEIO = True except ImportError: - pass # This is OK, we'll try to bitbang it! + pass # This is OK, we'll try to bitbang it! __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git" + class DHTBase: """ base support for DHT11 and DHT22 devices """ @@ -88,7 +91,7 @@ def _pulses_to_binary(self, pulses, start, stop): bit = 0 if pulses[bit_inx] > self.__hiLevel: bit = 1 - binary = binary<<1 | bit + binary = binary << 1 | bit hi_sig = not hi_sig @@ -104,7 +107,7 @@ def _get_pulses_pulseio(self): transition times starting with a low transition time. Normally pulses will have 81 elements for the DHT11/22 type devices. """ - pulses = array.array('H') + pulses = array.array("H") if _USE_PULSEIO: # The DHT type device use a specialize 1-wire protocol # The microprocessor first sends a LOW signal for a @@ -133,7 +136,7 @@ def _get_pulses_bitbang(self): transition times starting with a low transition time. Normally pulses will have 81 elements for the DHT11/22 type devices. """ - pulses = array.array('H') + pulses = array.array("H") with DigitalInOut(self._pin) as dhtpin: # we will bitbang if no pulsein capability transitions = [] @@ -143,19 +146,19 @@ def _get_pulses_bitbang(self): time.sleep(0.1) dhtpin.value = False time.sleep(0.001) - timestamp = time.monotonic() # take timestamp - dhtval = True # start with dht pin true because its pulled up + timestamp = time.monotonic() # take timestamp + dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT dhtpin.pull = Pull.UP while time.monotonic() - timestamp < 0.25: if dhtval != dhtpin.value: dhtval = not dhtval # we toggled - transitions.append(time.monotonic()) # save the timestamp + transitions.append(time.monotonic()) # save the timestamp # convert transtions to microsecond delta pulses: # use last 81 pulses transition_start = max(1, len(transitions) - 81) for i in range(transition_start, len(transitions)): - pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i-1])) + pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i - 1])) pulses.append(min(pulses_micro_sec, 65535)) return pulses @@ -171,20 +174,24 @@ def measure(self): # Initiate new reading if this is the first call or if sufficient delay # If delay not sufficient - return previous reading. # This allows back to back access for temperature and humidity for same reading - if (self._last_called == 0 or - (time.monotonic()-self._last_called) > delay_between_readings): + if ( + self._last_called == 0 + or (time.monotonic() - self._last_called) > delay_between_readings + ): self._last_called = time.monotonic() if _USE_PULSEIO: pulses = self._get_pulses_pulseio() else: pulses = self._get_pulses_bitbang() - #print(len(pulses), "pulses:", [x for x in pulses]) + # print(len(pulses), "pulses:", [x for x in pulses]) if len(pulses) >= 80: - buf = array.array('B') + buf = array.array("B") for byte_start in range(0, 80, 16): - buf.append(self._pulses_to_binary(pulses, byte_start, byte_start+16)) + buf.append( + self._pulses_to_binary(pulses, byte_start, byte_start + 16) + ) if self._dht11: # humidity is 1 byte @@ -193,10 +200,10 @@ def measure(self): self._temperature = buf[2] else: # humidity is 2 bytes - self._humidity = ((buf[0]<<8) | buf[1]) / 10 + self._humidity = ((buf[0] << 8) | buf[1]) / 10 # temperature is 2 bytes # MSB is sign, bits 0-14 are magnitude) - raw_temperature = (((buf[2] & 0x7f)<<8) | buf[3]) / 10 + raw_temperature = (((buf[2] & 0x7F) << 8) | buf[3]) / 10 # set sign if buf[2] & 0x80: raw_temperature = -raw_temperature @@ -207,7 +214,7 @@ def measure(self): chk_sum += b # checksum is the last byte - if chk_sum & 0xff != buf[4]: + if chk_sum & 0xFF != buf[4]: # check sum failed to validate raise RuntimeError("Checksum did not validate. Try again.") @@ -217,6 +224,7 @@ def measure(self): else: # Probably a connection issue! raise RuntimeError("DHT sensor not found, check wiring") + @property def temperature(self): """ temperature current reading. It makes sure a reading is available @@ -237,11 +245,13 @@ def humidity(self): self.measure() return self._humidity + class DHT11(DHTBase): """ Support for DHT11 device. :param ~board.Pin pin: digital pin used for communication """ + def __init__(self, pin): super().__init__(True, pin, 18000) @@ -251,5 +261,6 @@ class DHT22(DHTBase): :param ~board.Pin pin: digital pin used for communication """ + def __init__(self, pin): super().__init__(False, pin, 1000) diff --git a/docs/conf.py b/docs/conf.py index caed051..b628bfa 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -2,7 +2,8 @@ import os import sys -sys.path.insert(0, os.path.abspath('..')) + +sys.path.insert(0, os.path.abspath("..")) # -- General configuration ------------------------------------------------ @@ -10,39 +11,47 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.viewcode', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.viewcode", ] autodoc_mock_imports = ["pulseio"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None), - 'BusDevice': ('https://circuitpython.readthedocs.io/projects/busdevice/en/latest/', None), - 'Register': ('https://circuitpython.readthedocs.io/projects/register/en/latest/', None), - 'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", None), + "BusDevice": ( + "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + None, + ), + "Register": ( + "https://circuitpython.readthedocs.io/projects/register/en/latest/", + None, + ), + "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), +} # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] -source_suffix = '.rst' +source_suffix = ".rst" # The master toctree document. -master_doc = 'index' +master_doc = "index" # General information about the project. -project = u'Adafruit CircuitPython DHT Library' -copyright = u'2017 Mike McWethy' -author = u'Mike McWethy' +project = u"Adafruit CircuitPython DHT Library" +copyright = u"2017 Mike McWethy" +author = u"Mike McWethy" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u'1.0' +version = u"1.0" # The full version, including alpha/beta/rc tags. -release = u'1.0' +release = u"1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -54,7 +63,7 @@ # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This patterns also effect to html_static_path and html_extra_path -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', '.env', 'CODE_OF_CONDUCT.md'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", ".env", "CODE_OF_CONDUCT.md"] # The reST default role (used for this markup: `text`) to use for all # documents. @@ -66,7 +75,7 @@ add_function_parentheses = True # The name of the Pygments (syntax highlighting) style to use. -pygments_style = 'sphinx' +pygments_style = "sphinx" # If true, `todo` and `todoList` produce output, else they produce nothing. todo_include_todos = False @@ -80,59 +89,62 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get('READTHEDOCS', None) == 'True' +on_rtd = os.environ.get("READTHEDOCS", None) == "True" if not on_rtd: # only import and set the theme if we're building docs locally try: import sphinx_rtd_theme - html_theme = 'sphinx_rtd_theme' - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), '.'] + + html_theme = "sphinx_rtd_theme" + html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] except: - html_theme = 'default' - html_theme_path = ['.'] + html_theme = "default" + html_theme_path = ["."] else: - html_theme_path = ['.'] + html_theme_path = ["."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. # -html_favicon = '_static/favicon.ico' +html_favicon = "_static/favicon.ico" # Output file base name for HTML help builder. -htmlhelp_basename = 'AdafruitCircuitPythonDHTLibrarydoc' +htmlhelp_basename = "AdafruitCircuitPythonDHTLibrarydoc" # -- Options for LaTeX output --------------------------------------------- latex_elements = { - # The paper size ('letterpaper' or 'a4paper'). - # - # 'papersize': 'letterpaper', - - # The font size ('10pt', '11pt' or '12pt'). - # - # 'pointsize': '10pt', - - # Additional stuff for the LaTeX preamble. - # - # 'preamble': '', - - # Latex figure (float) alignment - # - # 'figure_align': 'htbp', + # The paper size ('letterpaper' or 'a4paper'). + # + # 'papersize': 'letterpaper', + # The font size ('10pt', '11pt' or '12pt'). + # + # 'pointsize': '10pt', + # Additional stuff for the LaTeX preamble. + # + # 'preamble': '', + # Latex figure (float) alignment + # + # 'figure_align': 'htbp', } # Grouping the document tree into LaTeX files. List of tuples # (source start file, target name, title, # author, documentclass [howto, manual, or own class]). latex_documents = [ - (master_doc, 'AdafruitCircuitPythonDHTLibrary.tex', u'Adafruit CircuitPython DHT Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitCircuitPythonDHTLibrary.tex", + u"Adafruit CircuitPython DHT Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -140,8 +152,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'adafruitCircuitPythonDHTlibrary', u'Adafruit CircuitPython DHT Library Documentation', - [author], 1) + ( + master_doc, + "adafruitCircuitPythonDHTlibrary", + u"Adafruit CircuitPython DHT Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -150,7 +167,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitCircuitPythonDHTLibrary', u'Adafruit CircuitPython DHT Library Documentation', - author, 'AdafruitCircuitPythonDHTLibrary', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitCircuitPythonDHTLibrary", + u"Adafruit CircuitPython DHT Library Documentation", + author, + "AdafruitCircuitPythonDHTLibrary", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index e07c078..9a054d1 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -11,8 +11,11 @@ temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity - print("Temp: {:.1f} F / {:.1f} C Humidity: {}% " - .format(temperature_f, temperature_c, humidity)) + print( + "Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format( + temperature_f, temperature_c, humidity + ) + ) except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index d3cb3a9..41baaa5 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -19,7 +19,7 @@ display = bcddigits.BCDDigits(spi, cs, nDigits=8) display.brightness(5) -#initial the dht device +# initial the dht device dhtDevice = adafruit_dht.DHT22(D2) while True: @@ -27,11 +27,11 @@ # show the values to the serial port temperature = dhtDevice.temperature * (9 / 5) + 32 humidity = dhtDevice.humidity - #print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) + # print("Temp: {:.1f} F Humidity: {}% ".format(temperature, humidity)) # now show the values on the 8 digit 7-segment display display.clear_all() - display.show_str(0, '{:5.1f}{:5.1f}'.format(temperature, humidity)) + display.show_str(0, "{:5.1f}{:5.1f}".format(temperature, humidity)) display.show() except RuntimeError as error: diff --git a/setup.py b/setup.py index 2817391..834fba2 100644 --- a/setup.py +++ b/setup.py @@ -7,6 +7,7 @@ # Always prefer setuptools over distutils from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -14,47 +15,38 @@ here = path.abspath(path.dirname(__file__)) # Get the long description from the README file -with open(path.join(here, 'README.rst'), encoding='utf-8') as f: +with open(path.join(here, "README.rst"), encoding="utf-8") as f: long_description = f.read() setup( - name='adafruit-circuitpython-dht', - + name="adafruit-circuitpython-dht", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython support for DHT11 and DHT22 type temperature/humidity devices', + setup_requires=["setuptools_scm"], + description="CircuitPython support for DHT11 and DHT22 type temperature/humidity devices", long_description=long_description, - long_description_content_type='text/x-rst', - + long_description_content_type="text/x-rst", # The project's main homepage. - url='https://github.com/adafruit/Adafruit_CircuitPython_DHT', - + url="https://github.com/adafruit/Adafruit_CircuitPython_DHT", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - - install_requires=['Adafruit-Blinka'], - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", + install_requires=["Adafruit-Blinka"], # Choose your license - license='MIT', - + license="MIT", # See https://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ - 'Development Status :: 3 - Alpha', - 'Intended Audience :: Developers', - 'Topic :: Software Development :: Libraries', - 'Topic :: System :: Hardware', - 'License :: OSI Approved :: MIT License', - 'Programming Language :: Python :: 3', - 'Programming Language :: Python :: 3.4', - 'Programming Language :: Python :: 3.5', + "Development Status :: 3 - Alpha", + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.4", + "Programming Language :: Python :: 3.5", ], - # What does your project relate to? - keywords='adafruit dht hardware sensors temperature humidity micropython circuitpython', - + keywords="adafruit dht hardware sensors temperature humidity micropython circuitpython", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). - py_modules=['adafruit_dht'], + py_modules=["adafruit_dht"], ) From 1833318bde1138203a453d2c0f1d2edc10ed0e56 Mon Sep 17 00:00:00 2001 From: Michael Lass Date: Tue, 28 Jan 2020 21:13:37 +0100 Subject: [PATCH 049/153] Do not update sensor values on error Currently, we update self._temperature and self._humidity, even if it turns out that the data returned by the sensor was bogus. If the user queries the data within two seconds after an error, they will actually get wrong data. Fix this by updating _temperature and _humidity attributes only if no error was detected. --- adafruit_dht.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 4c9083f..2f3c473 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -180,6 +180,9 @@ def measure(self): ): self._last_called = time.monotonic() + new_temperature = 0 + new_humidity = 0 + if _USE_PULSEIO: pulses = self._get_pulses_pulseio() else: @@ -195,19 +198,19 @@ def measure(self): if self._dht11: # humidity is 1 byte - self._humidity = buf[0] + new_humidity = buf[0] # temperature is 1 byte - self._temperature = buf[2] + new_temperature = buf[2] else: # humidity is 2 bytes - self._humidity = ((buf[0] << 8) | buf[1]) / 10 + new_humidity = ((buf[0] << 8) | buf[1]) / 10 # temperature is 2 bytes # MSB is sign, bits 0-14 are magnitude) raw_temperature = (((buf[2] & 0x7F) << 8) | buf[3]) / 10 # set sign if buf[2] & 0x80: raw_temperature = -raw_temperature - self._temperature = raw_temperature + new_temperature = raw_temperature # calc checksum chk_sum = 0 for b in buf[0:4]: @@ -220,11 +223,14 @@ def measure(self): elif len(pulses) >= 10: # We got *some* data just not 81 bits - raise RuntimeError("A full buffer was not returned. Try again.") + raise RuntimeError("A full buffer was not returned. Try again.") else: # Probably a connection issue! raise RuntimeError("DHT sensor not found, check wiring") + self._temperature = new_temperature + self._humidity = new_humidity + @property def temperature(self): """ temperature current reading. It makes sure a reading is available From e6880d74f633e72d3588eb62402117e5c266c7b4 Mon Sep 17 00:00:00 2001 From: Michael Lass Date: Tue, 28 Jan 2020 21:19:30 +0100 Subject: [PATCH 050/153] Reject humidity outside of range (0, 100) as unplausible --- adafruit_dht.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/adafruit_dht.py b/adafruit_dht.py index 2f3c473..6f40d54 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -221,6 +221,10 @@ def measure(self): # check sum failed to validate raise RuntimeError("Checksum did not validate. Try again.") + if new_humidity < 0 or new_humidity > 100: + # We received unplausible data + raise RuntimeError("Received unplausible data. Try again.") + elif len(pulses) >= 10: # We got *some* data just not 81 bits raise RuntimeError("A full buffer was not returned. Try again.") From efda9b8e9d4dae0e85c0b0854e9edbf0ce77fe1c Mon Sep 17 00:00:00 2001 From: Michael Lass Date: Sun, 2 Feb 2020 20:35:37 +0100 Subject: [PATCH 051/153] Reduce number of branches to make pylint happy --- adafruit_dht.py | 75 ++++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 39 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 6f40d54..fb2b188 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -189,48 +189,45 @@ def measure(self): pulses = self._get_pulses_bitbang() # print(len(pulses), "pulses:", [x for x in pulses]) - if len(pulses) >= 80: - buf = array.array("B") - for byte_start in range(0, 80, 16): - buf.append( - self._pulses_to_binary(pulses, byte_start, byte_start + 16) - ) - - if self._dht11: - # humidity is 1 byte - new_humidity = buf[0] - # temperature is 1 byte - new_temperature = buf[2] - else: - # humidity is 2 bytes - new_humidity = ((buf[0] << 8) | buf[1]) / 10 - # temperature is 2 bytes - # MSB is sign, bits 0-14 are magnitude) - raw_temperature = (((buf[2] & 0x7F) << 8) | buf[3]) / 10 - # set sign - if buf[2] & 0x80: - raw_temperature = -raw_temperature - new_temperature = raw_temperature - # calc checksum - chk_sum = 0 - for b in buf[0:4]: - chk_sum += b - - # checksum is the last byte - if chk_sum & 0xFF != buf[4]: - # check sum failed to validate - raise RuntimeError("Checksum did not validate. Try again.") - - if new_humidity < 0 or new_humidity > 100: - # We received unplausible data - raise RuntimeError("Received unplausible data. Try again.") - - elif len(pulses) >= 10: + if len(pulses) < 10: + # Probably a connection issue! + raise RuntimeError("DHT sensor not found, check wiring") + + if len(pulses) < 80: # We got *some* data just not 81 bits raise RuntimeError("A full buffer was not returned. Try again.") + + buf = array.array("B") + for byte_start in range(0, 80, 16): + buf.append(self._pulses_to_binary(pulses, byte_start, byte_start + 16)) + + if self._dht11: + # humidity is 1 byte + new_humidity = buf[0] + # temperature is 1 byte + new_temperature = buf[2] else: - # Probably a connection issue! - raise RuntimeError("DHT sensor not found, check wiring") + # humidity is 2 bytes + new_humidity = ((buf[0] << 8) | buf[1]) / 10 + # temperature is 2 bytes + # MSB is sign, bits 0-14 are magnitude) + new_temperature = (((buf[2] & 0x7F) << 8) | buf[3]) / 10 + # set sign + if buf[2] & 0x80: + new_temperature = -new_temperature + # calc checksum + chk_sum = 0 + for b in buf[0:4]: + chk_sum += b + + # checksum is the last byte + if chk_sum & 0xFF != buf[4]: + # check sum failed to validate + raise RuntimeError("Checksum did not validate. Try again.") + + if new_humidity < 0 or new_humidity > 100: + # We received unplausible data + raise RuntimeError("Received unplausible data. Try again.") self._temperature = new_temperature self._humidity = new_humidity From b770bb45adcbd7a395fd2e09f323f0e17dd32530 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Tue, 7 Apr 2020 15:02:31 -0500 Subject: [PATCH 052/153] build.yml: add black formatting check Signed-off-by: sommersoft --- .github/workflows/build.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1dad804..b6977a9 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -43,6 +43,9 @@ jobs: pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme - name: Library version run: git describe --dirty --always --tags + - name: Check formatting + run: | + black --check --target-version=py35 . - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) From b9acab847837b2fb97d630dbbc65d862c40a9991 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Wed, 8 Apr 2020 14:34:33 -0400 Subject: [PATCH 053/153] Black reformatting with Python 3 target. --- docs/conf.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index b628bfa..736346b 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -40,18 +40,18 @@ master_doc = "index" # General information about the project. -project = u"Adafruit CircuitPython DHT Library" -copyright = u"2017 Mike McWethy" -author = u"Mike McWethy" +project = "Adafruit CircuitPython DHT Library" +copyright = "2017 Mike McWethy" +author = "Mike McWethy" # The version info for the project you're documenting, acts as replacement for # |version| and |release|, also used in various other places throughout the # built documents. # # The short X.Y version. -version = u"1.0" +version = "1.0" # The full version, including alpha/beta/rc tags. -release = u"1.0" +release = "1.0" # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. @@ -141,7 +141,7 @@ ( master_doc, "AdafruitCircuitPythonDHTLibrary.tex", - u"Adafruit CircuitPython DHT Library Documentation", + "Adafruit CircuitPython DHT Library Documentation", author, "manual", ), @@ -155,7 +155,7 @@ ( master_doc, "adafruitCircuitPythonDHTlibrary", - u"Adafruit CircuitPython DHT Library Documentation", + "Adafruit CircuitPython DHT Library Documentation", [author], 1, ) @@ -170,7 +170,7 @@ ( master_doc, "AdafruitCircuitPythonDHTLibrary", - u"Adafruit CircuitPython DHT Library Documentation", + "Adafruit CircuitPython DHT Library Documentation", author, "AdafruitCircuitPythonDHTLibrary", "One line description of project.", From 35cc6b451822e3a0f77f21a6f109cb843d660887 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 8 Jul 2020 16:49:04 -0400 Subject: [PATCH 054/153] Fixed discord invite link --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index bdafd17..3b54da9 100644 --- a/README.rst +++ b/README.rst @@ -8,7 +8,7 @@ Introduction .. image :: https://img.shields.io/discord/327254708534116352.svg - :target: https://discord.gg/nBQh6qu + :target: https://adafru.it/discord :alt: Discord .. image:: https://github.com/adafruit/Adafruit_CircuitPython_DHT/workflows/Build%20CI/badge.svg From 5c1da73177420274319d2b42d9e18d003e352db9 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 16 Jul 2020 15:45:13 -0400 Subject: [PATCH 055/153] Deinitialize pulsein object on exit, gave option to choose whether or not to use pulseio --- adafruit_dht.py | 22 ++++++++++++++-------- examples/dht_simpletest.py | 7 ++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index fb2b188..bbd9984 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -51,7 +51,7 @@ class DHTBase: __hiLevel = 51 - def __init__(self, dht11, pin, trig_wait): + def __init__(self, dht11, pin, trig_wait, use_pulseio): """ :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication @@ -63,11 +63,17 @@ def __init__(self, dht11, pin, trig_wait): self._last_called = 0 self._humidity = None self._temperature = None + self._use_pulseio = use_pulseio # We don't use a context because linux-based systems are sluggish # and we're better off having a running process - if _USE_PULSEIO: + if self._use_pulseio: self.pulse_in = PulseIn(self._pin, 81, True) + def exit(self): + if self._use_pulseio: + print("De-initializing self.pulse_in") + self.pulse_in.deinit() + def _pulses_to_binary(self, pulses, start, stop): """Takes pulses, a list of transition times, and converts them to a 1's or 0's. The pulses array contains the transition times. @@ -108,7 +114,7 @@ def _get_pulses_pulseio(self): pulses will have 81 elements for the DHT11/22 type devices. """ pulses = array.array("H") - if _USE_PULSEIO: + if self._use_pulseio: # The DHT type device use a specialize 1-wire protocol # The microprocessor first sends a LOW signal for a # specific length of time. Then the device sends back a @@ -183,7 +189,7 @@ def measure(self): new_temperature = 0 new_humidity = 0 - if _USE_PULSEIO: + if self._use_pulseio: pulses = self._get_pulses_pulseio() else: pulses = self._get_pulses_bitbang() @@ -259,8 +265,8 @@ class DHT11(DHTBase): :param ~board.Pin pin: digital pin used for communication """ - def __init__(self, pin): - super().__init__(True, pin, 18000) + def __init__(self, pin, use_pulseio=_USE_PULSEIO): + super().__init__(True, pin, 18000, use_pulseio) class DHT22(DHTBase): @@ -269,5 +275,5 @@ class DHT22(DHTBase): :param ~board.Pin pin: digital pin used for communication """ - def __init__(self, pin): - super().__init__(False, pin, 1000) + def __init__(self, pin, use_pulseio=_USE_PULSEIO): + super().__init__(False, pin, 1000, use_pulseio) diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index 9a054d1..fcce603 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -3,7 +3,7 @@ import adafruit_dht # Initial the dht device, with data pin connected to: -dhtDevice = adafruit_dht.DHT22(board.D18) +dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) while True: try: @@ -20,5 +20,10 @@ except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going print(error.args[0]) + time.sleep(2.0) + continue + except Exception as error: + dhtDevice.exit() + raise error time.sleep(2.0) From 16400df13d2193dc43b8cc88e5dc6fc1b0c3db3f Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 17 Jul 2020 09:44:15 -0400 Subject: [PATCH 056/153] Cleaned up example --- examples/dht_simpletest.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index fcce603..ba2d806 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -3,7 +3,12 @@ import adafruit_dht # Initial the dht device, with data pin connected to: -dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) +dhtDevice = adafruit_dht.DHT22(board.D18) + +# you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio. +# This may be necessary on a Linux single board computer like the Raspberry Pi, +# but it will not work in CircuitPython. +#dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) while True: try: From 5ea758917ba854383f4b08e856efbef4d6727f02 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 17 Jul 2020 09:49:04 -0400 Subject: [PATCH 057/153] Formatting --- adafruit_dht.py | 1 + examples/dht_simpletest.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index bbd9984..3f6935b 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -70,6 +70,7 @@ def __init__(self, dht11, pin, trig_wait, use_pulseio): self.pulse_in = PulseIn(self._pin, 81, True) def exit(self): + """ Cleans up the PulseIn process. Must be called explicitly """ if self._use_pulseio: print("De-initializing self.pulse_in") self.pulse_in.deinit() diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index ba2d806..2b4cdec 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -8,7 +8,7 @@ # you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio. # This may be necessary on a Linux single board computer like the Raspberry Pi, # but it will not work in CircuitPython. -#dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) +# dhtDevice = adafruit_dht.DHT22(board.D18, use_pulseio=False) while True: try: From a554d72194a16ef11930e8325557643a26b5c693 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 24 Jul 2020 14:50:10 -0400 Subject: [PATCH 058/153] Added exception for trying to bitbang in circuitpython --- adafruit_dht.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/adafruit_dht.py b/adafruit_dht.py index 3f6935b..f6af34d 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -30,6 +30,7 @@ import array import time +from os import uname from digitalio import DigitalInOut, Pull, Direction _USE_PULSEIO = False @@ -64,6 +65,8 @@ def __init__(self, dht11, pin, trig_wait, use_pulseio): self._humidity = None self._temperature = None self._use_pulseio = use_pulseio + if "Linux" not in uname() and not self._use_pulseio: + raise Exception("Bitbanging is not supported when using CircuitPython.") # We don't use a context because linux-based systems are sluggish # and we're better off having a running process if self._use_pulseio: From 847ce956b08efc24015d871c464288d94efaa7b1 Mon Sep 17 00:00:00 2001 From: Michael Lass Date: Thu, 6 Aug 2020 14:52:37 +0200 Subject: [PATCH 059/153] Immediately pause pulse_in after initialization Right now, pulse_in is active until the first reading and only paused after that. Let's immediately pause it to free up the CPU. --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index fb2b188..137994a 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -67,6 +67,7 @@ def __init__(self, dht11, pin, trig_wait): # and we're better off having a running process if _USE_PULSEIO: self.pulse_in = PulseIn(self._pin, 81, True) + self.pulse_in.pause() def _pulses_to_binary(self, pulses, start, stop): """Takes pulses, a list of transition times, and converts @@ -114,7 +115,6 @@ def _get_pulses_pulseio(self): # specific length of time. Then the device sends back a # series HIGH and LOW signals. The length the HIGH signals # represents the device values. - self.pulse_in.pause() self.pulse_in.clear() self.pulse_in.resume(self._trig_wait) From a515f920f5c187c04f9e2fb4deb299c53dcb5218 Mon Sep 17 00:00:00 2001 From: Jerry Needell Date: Wed, 19 Aug 2020 14:44:39 -0400 Subject: [PATCH 060/153] add docstring for use_pulseio kwarg --- adafruit_dht.py | 1 + 1 file changed, 1 insertion(+) diff --git a/adafruit_dht.py b/adafruit_dht.py index f6af34d..973a9c2 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -57,6 +57,7 @@ def __init__(self, dht11, pin, trig_wait, use_pulseio): :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication :param int trig_wait: length of time to hold trigger in LOW state (microseconds) + :param boolean use_pulseio: False to force bitbang when pulseio available (only with Blinka) """ self._dht11 = dht11 self._pin = pin From 9a0cb0be14635de9e69f5a5100991cfa2b360c62 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 31 Aug 2020 12:25:24 -0400 Subject: [PATCH 061/153] Linted --- examples/dht_to_led_display.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index 41baaa5..2a116ee 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -8,8 +8,8 @@ from board import D2, TX, RX, D1 import busio import digitalio -import adafruit_dht from adafruit_max7219 import bcddigits +import adafruit_dht clk = RX From c9b2e164529d02efda38c7dc2ef8990f5e3ce8a9 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Mon, 14 Dec 2020 09:28:06 +0100 Subject: [PATCH 062/153] Fix issue 54 Add NotImplementedError on catched exceptions. --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index e7f1a64..96bd411 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -38,7 +38,7 @@ from pulseio import PulseIn _USE_PULSEIO = True -except ImportError: +except (ImportError, NotImplementedError): pass # This is OK, we'll try to bitbang it! From 1d3929fe561a4e26da83c7fe04565c02790b80bd Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Mon, 14 Dec 2020 09:36:21 +0100 Subject: [PATCH 063/153] Fix issue #32 --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index e7f1a64..bc14bfd 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -160,7 +160,7 @@ def _get_pulses_bitbang(self): timestamp = time.monotonic() # take timestamp dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT - dhtpin.pull = Pull.UP + dhtpin.pull = None while time.monotonic() - timestamp < 0.25: if dhtval != dhtpin.value: dhtval = not dhtval # we toggled From bcf42064e32104b8879cb200372ffe9d55c4ac3b Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Mon, 14 Dec 2020 09:42:23 +0100 Subject: [PATCH 064/153] Update adafruit_dht.py Fix issue on linting removing not used variable from digitalio --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index bc14bfd..6e310e5 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -31,7 +31,7 @@ import array import time from os import uname -from digitalio import DigitalInOut, Pull, Direction +from digitalio import DigitalInOut, Direction _USE_PULSEIO = False try: From f61a5103382e96571597661d1b9b4345bdd171f6 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Mon, 14 Dec 2020 19:56:05 +0100 Subject: [PATCH 065/153] Update adafruit_dht.py Catch the exception raised by blinka. --- adafruit_dht.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 6e310e5..be869b2 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -31,7 +31,7 @@ import array import time from os import uname -from digitalio import DigitalInOut, Direction +from digitalio import DigitalInOut, Pull, Direction _USE_PULSEIO = False try: @@ -160,7 +160,15 @@ def _get_pulses_bitbang(self): timestamp = time.monotonic() # take timestamp dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT - dhtpin.pull = None + + try: + dhtpin.pull = Pull.UP + # Catch the NotImplementedError raised because + # blinka.microcontroller.generic_linux.libgpiod_pin does not support + # internal pull resistors. + except NotImplementedError: + dhtpin.pull = None + while time.monotonic() - timestamp < 0.25: if dhtval != dhtpin.value: dhtval = not dhtval # we toggled From 76f21edd484697378d2bc9ddcd8ffa6393150496 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 15:06:44 -0500 Subject: [PATCH 066/153] Added pre-commit and SPDX copyright Signed-off-by: dherrada --- .github/workflows/build.yml | 28 ++++++++++++++++++++++++---- .github/workflows/release.yml | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b6977a9..59baa53 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Build CI on: [pull_request, push] @@ -38,20 +42,36 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, black, & Sphinx + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall pylint black==19.10b0 Sphinx sphinx-rtd-theme + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - - name: Check formatting + - name: Pre-commit hooks run: | - black --check --target-version=py35 . + pre-commit run --all-files - name: PyLint run: | pylint $( find . -path './adafruit*.py' ) ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . + - name: Archive bundles + uses: actions/upload-artifact@v2 + with: + name: bundles + path: ${{ github.workspace }}/bundles/ - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html + - name: Check For setup.py + id: need-pypi + run: | + echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + - name: Build Python package + if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + run: | + pip install --upgrade setuptools wheel twine readme_renderer testresources + python setup.py sdist + python setup.py bdist_wheel --universal + twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 18efb9c..6d0015a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + name: Release Actions on: From 438edff3e92f35b932c4fd908845f811331e47ec Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 11 Jan 2021 16:06:47 -0500 Subject: [PATCH 067/153] Added pre-commit-config file Signed-off-by: dherrada --- .pre-commit-config.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..aab5f1c --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# +# SPDX-License-Identifier: Unlicense + +repos: +- repo: https://github.com/python/black + rev: stable + hooks: + - id: black +- repo: https://github.com/fsfe/reuse-tool + rev: latest + hooks: + - id: reuse +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.3.0 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace From 8d393f32b8530b05514b6c1fa8705aeccd352d8f Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 14 Jan 2021 13:25:08 -0500 Subject: [PATCH 068/153] Ran pre-commit, added licenses --- .gitignore | 4 + .pylintrc | 4 + .readthedocs.yml | 5 +- CODE_OF_CONDUCT.md | 14 +- LICENSES/CC-BY-4.0.txt | 324 +++++++++++++++++++++++++++++++ LICENSES/MIT.txt | 19 ++ LICENSES/Unlicense.txt | 20 ++ README.rst | 6 +- README.rst.license | 3 + adafruit_dht.py | 60 ++---- docs/_static/favicon.ico.license | 3 + docs/api.rst.license | 3 + docs/conf.py | 4 + docs/examples.rst.license | 3 + docs/index.rst.license | 3 + examples/dht_simpletest.py | 3 + examples/dht_to_led_display.py | 3 + requirements.txt | 4 + setup.py | 4 + 19 files changed, 442 insertions(+), 47 deletions(-) create mode 100644 LICENSES/CC-BY-4.0.txt create mode 100644 LICENSES/MIT.txt create mode 100644 LICENSES/Unlicense.txt create mode 100644 README.rst.license create mode 100644 docs/_static/favicon.ico.license create mode 100644 docs/api.rst.license create mode 100644 docs/examples.rst.license create mode 100644 docs/index.rst.license diff --git a/.gitignore b/.gitignore index 1be1c4b..9647e71 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + *.mpy .idea __pycache__ diff --git a/.pylintrc b/.pylintrc index 5a43a10..820072b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + [MASTER] # A comma-separated list of package or module names from where C extensions may diff --git a/.readthedocs.yml b/.readthedocs.yml index 78a4671..ffa84c4 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,4 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + python: version: 3 requirements_file: requirements.txt - diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index 134d510..8a55c07 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,3 +1,9 @@ + + # Adafruit Community Code of Conduct ## Our Pledge @@ -43,7 +49,7 @@ Examples of unacceptable behavior by participants include: The goal of the standards and moderation guidelines outlined here is to build and maintain a respectful community. We ask that you don’t just aim to be -"technically unimpeachable", but rather try to be your best self. +"technically unimpeachable", but rather try to be your best self. We value many things beyond technical expertise, including collaboration and supporting others within our community. Providing a positive experience for @@ -74,9 +80,9 @@ You may report in the following ways: In any situation, you may send an email to . On the Adafruit Discord, you may send an open message from any channel -to all Community Moderators by tagging @community moderators. You may -also send an open message from any channel, or a direct message to -@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, +to all Community Moderators by tagging @community moderators. You may +also send an open message from any channel, or a direct message to +@kattni#1507, @tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, @Mr. Certainly#0472 or @Andon#8175. Email and direct message reports will be kept confidential. diff --git a/LICENSES/CC-BY-4.0.txt b/LICENSES/CC-BY-4.0.txt new file mode 100644 index 0000000..3f92dfc --- /dev/null +++ b/LICENSES/CC-BY-4.0.txt @@ -0,0 +1,324 @@ +Creative Commons Attribution 4.0 International Creative Commons Corporation +("Creative Commons") is not a law firm and does not provide legal services +or legal advice. Distribution of Creative Commons public licenses does not +create a lawyer-client or other relationship. Creative Commons makes its licenses +and related information available on an "as-is" basis. Creative Commons gives +no warranties regarding its licenses, any material licensed under their terms +and conditions, or any related information. Creative Commons disclaims all +liability for damages resulting from their use to the fullest extent possible. + +Using Creative Commons Public Licenses + +Creative Commons public licenses provide a standard set of terms and conditions +that creators and other rights holders may use to share original works of +authorship and other material subject to copyright and certain other rights +specified in the public license below. The following considerations are for +informational purposes only, are not exhaustive, and do not form part of our +licenses. + +Considerations for licensors: Our public licenses are intended for use by +those authorized to give the public permission to use material in ways otherwise +restricted by copyright and certain other rights. Our licenses are irrevocable. +Licensors should read and understand the terms and conditions of the license +they choose before applying it. Licensors should also secure all rights necessary +before applying our licenses so that the public can reuse the material as +expected. Licensors should clearly mark any material not subject to the license. +This includes other CC-licensed material, or material used under an exception +or limitation to copyright. More considerations for licensors : wiki.creativecommons.org/Considerations_for_licensors + +Considerations for the public: By using one of our public licenses, a licensor +grants the public permission to use the licensed material under specified +terms and conditions. If the licensor's permission is not necessary for any +reason–for example, because of any applicable exception or limitation to copyright–then +that use is not regulated by the license. Our licenses grant only permissions +under copyright and certain other rights that a licensor has authority to +grant. Use of the licensed material may still be restricted for other reasons, +including because others have copyright or other rights in the material. A +licensor may make special requests, such as asking that all changes be marked +or described. Although not required by our licenses, you are encouraged to +respect those requests where reasonable. More considerations for the public +: wiki.creativecommons.org/Considerations_for_licensees Creative Commons Attribution +4.0 International Public License + +By exercising the Licensed Rights (defined below), You accept and agree to +be bound by the terms and conditions of this Creative Commons Attribution +4.0 International Public License ("Public License"). To the extent this Public +License may be interpreted as a contract, You are granted the Licensed Rights +in consideration of Your acceptance of these terms and conditions, and the +Licensor grants You such rights in consideration of benefits the Licensor +receives from making the Licensed Material available under these terms and +conditions. + +Section 1 – Definitions. + +a. Adapted Material means material subject to Copyright and Similar Rights +that is derived from or based upon the Licensed Material and in which the +Licensed Material is translated, altered, arranged, transformed, or otherwise +modified in a manner requiring permission under the Copyright and Similar +Rights held by the Licensor. For purposes of this Public License, where the +Licensed Material is a musical work, performance, or sound recording, Adapted +Material is always produced where the Licensed Material is synched in timed +relation with a moving image. + +b. Adapter's License means the license You apply to Your Copyright and Similar +Rights in Your contributions to Adapted Material in accordance with the terms +and conditions of this Public License. + +c. Copyright and Similar Rights means copyright and/or similar rights closely +related to copyright including, without limitation, performance, broadcast, +sound recording, and Sui Generis Database Rights, without regard to how the +rights are labeled or categorized. For purposes of this Public License, the +rights specified in Section 2(b)(1)-(2) are not Copyright and Similar Rights. + +d. Effective Technological Measures means those measures that, in the absence +of proper authority, may not be circumvented under laws fulfilling obligations +under Article 11 of the WIPO Copyright Treaty adopted on December 20, 1996, +and/or similar international agreements. + +e. Exceptions and Limitations means fair use, fair dealing, and/or any other +exception or limitation to Copyright and Similar Rights that applies to Your +use of the Licensed Material. + +f. Licensed Material means the artistic or literary work, database, or other +material to which the Licensor applied this Public License. + +g. Licensed Rights means the rights granted to You subject to the terms and +conditions of this Public License, which are limited to all Copyright and +Similar Rights that apply to Your use of the Licensed Material and that the +Licensor has authority to license. + +h. Licensor means the individual(s) or entity(ies) granting rights under this +Public License. + +i. Share means to provide material to the public by any means or process that +requires permission under the Licensed Rights, such as reproduction, public +display, public performance, distribution, dissemination, communication, or +importation, and to make material available to the public including in ways +that members of the public may access the material from a place and at a time +individually chosen by them. + +j. Sui Generis Database Rights means rights other than copyright resulting +from Directive 96/9/EC of the European Parliament and of the Council of 11 +March 1996 on the legal protection of databases, as amended and/or succeeded, +as well as other essentially equivalent rights anywhere in the world. + +k. You means the individual or entity exercising the Licensed Rights under +this Public License. Your has a corresponding meaning. + +Section 2 – Scope. + + a. License grant. + +1. Subject to the terms and conditions of this Public License, the Licensor +hereby grants You a worldwide, royalty-free, non-sublicensable, non-exclusive, +irrevocable license to exercise the Licensed Rights in the Licensed Material +to: + + A. reproduce and Share the Licensed Material, in whole or in part; and + + B. produce, reproduce, and Share Adapted Material. + +2. Exceptions and Limitations. For the avoidance of doubt, where Exceptions +and Limitations apply to Your use, this Public License does not apply, and +You do not need to comply with its terms and conditions. + + 3. Term. The term of this Public License is specified in Section 6(a). + +4. Media and formats; technical modifications allowed. The Licensor authorizes +You to exercise the Licensed Rights in all media and formats whether now known +or hereafter created, and to make technical modifications necessary to do +so. The Licensor waives and/or agrees not to assert any right or authority +to forbid You from making technical modifications necessary to exercise the +Licensed Rights, including technical modifications necessary to circumvent +Effective Technological Measures. For purposes of this Public License, simply +making modifications authorized by this Section 2(a)(4) never produces Adapted +Material. + + 5. Downstream recipients. + +A. Offer from the Licensor – Licensed Material. Every recipient of the Licensed +Material automatically receives an offer from the Licensor to exercise the +Licensed Rights under the terms and conditions of this Public License. + +B. No downstream restrictions. You may not offer or impose any additional +or different terms or conditions on, or apply any Effective Technological +Measures to, the Licensed Material if doing so restricts exercise of the Licensed +Rights by any recipient of the Licensed Material. + +6. No endorsement. Nothing in this Public License constitutes or may be construed +as permission to assert or imply that You are, or that Your use of the Licensed +Material is, connected with, or sponsored, endorsed, or granted official status +by, the Licensor or others designated to receive attribution as provided in +Section 3(a)(1)(A)(i). + + b. Other rights. + +1. Moral rights, such as the right of integrity, are not licensed under this +Public License, nor are publicity, privacy, and/or other similar personality +rights; however, to the extent possible, the Licensor waives and/or agrees +not to assert any such rights held by the Licensor to the limited extent necessary +to allow You to exercise the Licensed Rights, but not otherwise. + +2. Patent and trademark rights are not licensed under this Public License. + +3. To the extent possible, the Licensor waives any right to collect royalties +from You for the exercise of the Licensed Rights, whether directly or through +a collecting society under any voluntary or waivable statutory or compulsory +licensing scheme. In all other cases the Licensor expressly reserves any right +to collect such royalties. + +Section 3 – License Conditions. + +Your exercise of the Licensed Rights is expressly made subject to the following +conditions. + + a. Attribution. + +1. If You Share the Licensed Material (including in modified form), You must: + +A. retain the following if it is supplied by the Licensor with the Licensed +Material: + +i. identification of the creator(s) of the Licensed Material and any others +designated to receive attribution, in any reasonable manner requested by the +Licensor (including by pseudonym if designated); + + ii. a copyright notice; + + iii. a notice that refers to this Public License; + + iv. a notice that refers to the disclaimer of warranties; + +v. a URI or hyperlink to the Licensed Material to the extent reasonably practicable; + +B. indicate if You modified the Licensed Material and retain an indication +of any previous modifications; and + +C. indicate the Licensed Material is licensed under this Public License, and +include the text of, or the URI or hyperlink to, this Public License. + +2. You may satisfy the conditions in Section 3(a)(1) in any reasonable manner +based on the medium, means, and context in which You Share the Licensed Material. +For example, it may be reasonable to satisfy the conditions by providing a +URI or hyperlink to a resource that includes the required information. + +3. If requested by the Licensor, You must remove any of the information required +by Section 3(a)(1)(A) to the extent reasonably practicable. + +4. If You Share Adapted Material You produce, the Adapter's License You apply +must not prevent recipients of the Adapted Material from complying with this +Public License. + +Section 4 – Sui Generis Database Rights. + +Where the Licensed Rights include Sui Generis Database Rights that apply to +Your use of the Licensed Material: + +a. for the avoidance of doubt, Section 2(a)(1) grants You the right to extract, +reuse, reproduce, and Share all or a substantial portion of the contents of +the database; + +b. if You include all or a substantial portion of the database contents in +a database in which You have Sui Generis Database Rights, then the database +in which You have Sui Generis Database Rights (but not its individual contents) +is Adapted Material; and + +c. You must comply with the conditions in Section 3(a) if You Share all or +a substantial portion of the contents of the database. + +For the avoidance of doubt, this Section 4 supplements and does not replace +Your obligations under this Public License where the Licensed Rights include +other Copyright and Similar Rights. + +Section 5 – Disclaimer of Warranties and Limitation of Liability. + +a. Unless otherwise separately undertaken by the Licensor, to the extent possible, +the Licensor offers the Licensed Material as-is and as-available, and makes +no representations or warranties of any kind concerning the Licensed Material, +whether express, implied, statutory, or other. This includes, without limitation, +warranties of title, merchantability, fitness for a particular purpose, non-infringement, +absence of latent or other defects, accuracy, or the presence or absence of +errors, whether or not known or discoverable. Where disclaimers of warranties +are not allowed in full or in part, this disclaimer may not apply to You. + +b. To the extent possible, in no event will the Licensor be liable to You +on any legal theory (including, without limitation, negligence) or otherwise +for any direct, special, indirect, incidental, consequential, punitive, exemplary, +or other losses, costs, expenses, or damages arising out of this Public License +or use of the Licensed Material, even if the Licensor has been advised of +the possibility of such losses, costs, expenses, or damages. Where a limitation +of liability is not allowed in full or in part, this limitation may not apply +to You. + +c. The disclaimer of warranties and limitation of liability provided above +shall be interpreted in a manner that, to the extent possible, most closely +approximates an absolute disclaimer and waiver of all liability. + +Section 6 – Term and Termination. + +a. This Public License applies for the term of the Copyright and Similar Rights +licensed here. However, if You fail to comply with this Public License, then +Your rights under this Public License terminate automatically. + +b. Where Your right to use the Licensed Material has terminated under Section +6(a), it reinstates: + +1. automatically as of the date the violation is cured, provided it is cured +within 30 days of Your discovery of the violation; or + + 2. upon express reinstatement by the Licensor. + +c. For the avoidance of doubt, this Section 6(b) does not affect any right +the Licensor may have to seek remedies for Your violations of this Public +License. + +d. For the avoidance of doubt, the Licensor may also offer the Licensed Material +under separate terms or conditions or stop distributing the Licensed Material +at any time; however, doing so will not terminate this Public License. + + e. Sections 1, 5, 6, 7, and 8 survive termination of this Public License. + +Section 7 – Other Terms and Conditions. + +a. The Licensor shall not be bound by any additional or different terms or +conditions communicated by You unless expressly agreed. + +b. Any arrangements, understandings, or agreements regarding the Licensed +Material not stated herein are separate from and independent of the terms +and conditions of this Public License. + +Section 8 – Interpretation. + +a. For the avoidance of doubt, this Public License does not, and shall not +be interpreted to, reduce, limit, restrict, or impose conditions on any use +of the Licensed Material that could lawfully be made without permission under +this Public License. + +b. To the extent possible, if any provision of this Public License is deemed +unenforceable, it shall be automatically reformed to the minimum extent necessary +to make it enforceable. If the provision cannot be reformed, it shall be severed +from this Public License without affecting the enforceability of the remaining +terms and conditions. + +c. No term or condition of this Public License will be waived and no failure +to comply consented to unless expressly agreed to by the Licensor. + +d. Nothing in this Public License constitutes or may be interpreted as a limitation +upon, or waiver of, any privileges and immunities that apply to the Licensor +or You, including from the legal processes of any jurisdiction or authority. + +Creative Commons is not a party to its public licenses. Notwithstanding, Creative +Commons may elect to apply one of its public licenses to material it publishes +and in those instances will be considered the "Licensor." The text of the +Creative Commons public licenses is dedicated to the public domain under the +CC0 Public Domain Dedication. Except for the limited purpose of indicating +that material is shared under a Creative Commons public license or as otherwise +permitted by the Creative Commons policies published at creativecommons.org/policies, +Creative Commons does not authorize the use of the trademark "Creative Commons" +or any other trademark or logo of Creative Commons without its prior written +consent including, without limitation, in connection with any unauthorized +modifications to any of its public licenses or any other arrangements, understandings, +or agreements concerning use of licensed material. For the avoidance of doubt, +this paragraph does not form part of the public licenses. + +Creative Commons may be contacted at creativecommons.org. diff --git a/LICENSES/MIT.txt b/LICENSES/MIT.txt new file mode 100644 index 0000000..204b93d --- /dev/null +++ b/LICENSES/MIT.txt @@ -0,0 +1,19 @@ +MIT License Copyright (c) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice (including the next +paragraph) shall be included in all copies or substantial portions of the +Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF +OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/LICENSES/Unlicense.txt b/LICENSES/Unlicense.txt new file mode 100644 index 0000000..24a8f90 --- /dev/null +++ b/LICENSES/Unlicense.txt @@ -0,0 +1,20 @@ +This is free and unencumbered software released into the public domain. + +Anyone is free to copy, modify, publish, use, compile, sell, or distribute +this software, either in source code form or as a compiled binary, for any +purpose, commercial or non-commercial, and by any means. + +In jurisdictions that recognize copyright laws, the author or authors of this +software dedicate any and all copyright interest in the software to the public +domain. We make this dedication for the benefit of the public at large and +to the detriment of our heirs and successors. We intend this dedication to +be an overt act of relinquishment in perpetuity of all present and future +rights to this software under copyright law. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS +BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH +THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. For more information, +please refer to diff --git a/README.rst b/README.rst index 3b54da9..1e4513e 100644 --- a/README.rst +++ b/README.rst @@ -58,8 +58,8 @@ Usage Example Hardware Set-up ---------------- -The DHT11 and DHT22 devices both need a pull-resistor on the data signal wire. -This resistor is in the range of 1k to 5k. Please check your device datasheet for the +The DHT11 and DHT22 devices both need a pull-resistor on the data signal wire. +This resistor is in the range of 1k to 5k. Please check your device datasheet for the appropriate value. Basics @@ -99,7 +99,7 @@ Now get the temperature and humidity values temperature = dht_device.temperature humidity = dht_device.humidity -These properties may raise an exception if a problem occurs. You should use try/raise +These properties may raise an exception if a problem occurs. You should use try/raise logic and catch RuntimeError and then retry getting the values after at least 2 seconds. If you try again to get a result within 2 seconds, cached values are returned. diff --git a/README.rst.license b/README.rst.license new file mode 100644 index 0000000..11cd75d --- /dev/null +++ b/README.rst.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries + +SPDX-License-Identifier: MIT diff --git a/adafruit_dht.py b/adafruit_dht.py index f02aecb..f6fee58 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -1,24 +1,7 @@ -# The MIT License (MIT) +# SPDX-FileCopyrightText: 2017 Mike McWethy for Adafruit Industries # -# Copyright (c) 2017 Mike McWethy for Adafruit Industries -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. +# SPDX-License-Identifier: MIT + """ :mod:`adafruit_dhtlib` ====================== @@ -47,8 +30,7 @@ class DHTBase: - """ base support for DHT11 and DHT22 devices - """ + """base support for DHT11 and DHT22 devices""" __hiLevel = 51 @@ -110,7 +92,7 @@ def _pulses_to_binary(self, pulses, start, stop): return binary def _get_pulses_pulseio(self): - """ _get_pulses implements the communication protcol for + """_get_pulses implements the communication protcol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the return signal lengths. @@ -138,7 +120,7 @@ def _get_pulses_pulseio(self): return pulses def _get_pulses_bitbang(self): - """ _get_pulses implements the communication protcol for + """_get_pulses implements the communication protcol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the return signal lengths. @@ -182,12 +164,12 @@ def _get_pulses_bitbang(self): return pulses def measure(self): - """ measure runs the communications to the DHT11/22 type device. - if successful, the class properties temperature and humidity will - return the reading returned from the device. + """measure runs the communications to the DHT11/22 type device. + if successful, the class properties temperature and humidity will + return the reading returned from the device. - Raises RuntimeError exception for checksum failure and for insuffcient - data returned from the device (try again) + Raises RuntimeError exception for checksum failure and for insuffcient + data returned from the device (try again) """ delay_between_readings = 2 # 2 seconds per read according to datasheet # Initiate new reading if this is the first call or if sufficient delay @@ -253,29 +235,29 @@ def measure(self): @property def temperature(self): - """ temperature current reading. It makes sure a reading is available + """temperature current reading. It makes sure a reading is available - Raises RuntimeError exception for checksum failure and for insuffcient - data returned from the device (try again) + Raises RuntimeError exception for checksum failure and for insuffcient + data returned from the device (try again) """ self.measure() return self._temperature @property def humidity(self): - """ humidity current reading. It makes sure a reading is available + """humidity current reading. It makes sure a reading is available - Raises RuntimeError exception for checksum failure and for insuffcient - data returned from the device (try again) + Raises RuntimeError exception for checksum failure and for insuffcient + data returned from the device (try again) """ self.measure() return self._humidity class DHT11(DHTBase): - """ Support for DHT11 device. + """Support for DHT11 device. - :param ~board.Pin pin: digital pin used for communication + :param ~board.Pin pin: digital pin used for communication """ def __init__(self, pin, use_pulseio=_USE_PULSEIO): @@ -283,9 +265,9 @@ def __init__(self, pin, use_pulseio=_USE_PULSEIO): class DHT22(DHTBase): - """ Support for DHT22 device. + """Support for DHT22 device. - :param ~board.Pin pin: digital pin used for communication + :param ~board.Pin pin: digital pin used for communication """ def __init__(self, pin, use_pulseio=_USE_PULSEIO): diff --git a/docs/_static/favicon.ico.license b/docs/_static/favicon.ico.license new file mode 100644 index 0000000..86a3fbf --- /dev/null +++ b/docs/_static/favicon.ico.license @@ -0,0 +1,3 @@ +SPDX-FileCopyrightText: 2018 Phillip Torrone for Adafruit Industries + +SPDX-License-Identifier: CC-BY-4.0 diff --git a/docs/api.rst.license b/docs/api.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/api.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/conf.py b/docs/conf.py index 736346b..379eb5f 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,5 +1,9 @@ # -*- coding: utf-8 -*- +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + import os import sys diff --git a/docs/examples.rst.license b/docs/examples.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/examples.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/docs/index.rst.license b/docs/index.rst.license new file mode 100644 index 0000000..9aae48d --- /dev/null +++ b/docs/index.rst.license @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index 2b4cdec..5b3a482 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + import time import board import adafruit_dht diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index 2a116ee..76434ca 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-License-Identifier: MIT + """ example of reading temperature and humidity from a DHT device and displaying results to the serial port and a 8 digit 7-segment display diff --git a/requirements.txt b/requirements.txt index edf9394..17a850d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,5 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + Adafruit-Blinka diff --git a/setup.py b/setup.py index 834fba2..a6cc107 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,7 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: MIT + """A setuptools based setup module. See: From e22d289ab480468fa305a451e3b9c1961c7f0fb2 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Feb 2021 16:38:51 -0500 Subject: [PATCH 069/153] Hardcoded Black and REUSE versions Signed-off-by: dherrada --- .pre-commit-config.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aab5f1c..07f886c 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,11 +4,11 @@ repos: - repo: https://github.com/python/black - rev: stable + rev: 20.8b1 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: latest + rev: v0.12.1 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks From ef109723e43e999492fdf46d5e657a55505edfd9 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 13 Feb 2021 20:12:52 -0500 Subject: [PATCH 070/153] Change in the Bitbang Trigger calculation --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index f6fee58..7a61d2f 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,7 +138,7 @@ def _get_pulses_bitbang(self): dhtpin.value = True time.sleep(0.1) dhtpin.value = False - time.sleep(0.001) + time.sleep(self._trig_wait // 1000000) # Using the time to pull-down the line according to DHT Model timestamp = time.monotonic() # take timestamp dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT From 85b6a367f9389f0b03b85e1399950c6b8872e40e Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sat, 13 Feb 2021 20:37:30 -0500 Subject: [PATCH 071/153] Pylint and black verification --- adafruit_dht.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 7a61d2f..102e8e5 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -138,7 +138,8 @@ def _get_pulses_bitbang(self): dhtpin.value = True time.sleep(0.1) dhtpin.value = False - time.sleep(self._trig_wait // 1000000) # Using the time to pull-down the line according to DHT Model + # Using the time to pull-down the line according to DHT Model + time.sleep(self._trig_wait // 1000000) timestamp = time.monotonic() # take timestamp dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT From 64e77fd87922bde0941d53a7a21b42eff06aedae Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Thu, 25 Feb 2021 18:42:44 -0500 Subject: [PATCH 072/153] Correction of the integer in the new time sleep logic --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 102e8e5..2e76eb9 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -139,7 +139,7 @@ def _get_pulses_bitbang(self): time.sleep(0.1) dhtpin.value = False # Using the time to pull-down the line according to DHT Model - time.sleep(self._trig_wait // 1000000) + time.sleep(self._trig_wait / 1000000) timestamp = time.monotonic() # take timestamp dhtval = True # start with dht pin true because its pulled up dhtpin.direction = Direction.INPUT From e719800399dae7edfb30abf685ebab152880877b Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 16:46:17 -0500 Subject: [PATCH 073/153] Removed pylint process from github workflow Signed-off-by: dherrada --- .github/workflows/build.yml | 8 ++------ .pre-commit-config.yaml | 15 +++++++++++++++ .pylintrc | 2 +- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 59baa53..621d5ef 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,18 +42,14 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks run: | pre-commit run --all-files - - name: PyLint - run: | - pylint $( find . -path './adafruit*.py' ) - ([[ ! -d "examples" ]] || pylint --disable=missing-docstring,invalid-name,bad-whitespace $( find . -path "./examples/*.py" )) - name: Build assets run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - name: Archive bundles diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 07f886c..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,3 +17,18 @@ repos: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace +- repo: https://github.com/pycqa/pylint + rev: pylint-2.7.1 + hooks: + - id: pylint + name: pylint (library code) + types: [python] + exclude: "^(docs/|examples/|setup.py$)" +- repo: local + hooks: + - id: pylint_examples + name: pylint (examples code) + description: Run pylint rules on "examples/*.py" files + entry: /usr/bin/env bash -c + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + language: system diff --git a/.pylintrc b/.pylintrc index 820072b..89dd17d 100644 --- a/.pylintrc +++ b/.pylintrc @@ -249,7 +249,7 @@ ignore-comments=yes ignore-docstrings=yes # Ignore imports when computing similarities. -ignore-imports=no +ignore-imports=yes # Minimum lines number of a similarity. min-similarity-lines=4 From ceb883d09587612d2f96037f54c93805e4175db3 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 2 Mar 2021 17:17:50 -0500 Subject: [PATCH 074/153] Re-added pylint install to build.yml Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 621d5ef..3baf502 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit + - name: Pip install pylint, Sphinx, pre-commit run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks From d00163889f1de5e38048c3ca27c6940a7ce90d1b Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 13:33:02 +0100 Subject: [PATCH 075/153] Create dht_time_calibration.py Addition of a script to test best timing for DHT sensor. --- examples/dht_time_calibration.py | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 examples/dht_time_calibration.py diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py new file mode 100644 index 0000000..a0857c4 --- /dev/null +++ b/examples/dht_time_calibration.py @@ -0,0 +1,84 @@ +import json +import time + +import board + +import adafruit_dht + +pin_to_use = 'PG6' + +# Maximum number of tries per timing +max_retries_per_time = 10 +# Minimum time from where to start testing +min_time = 500 +# Maximum time on where to stop testing +max_time = 2000 +# Increment on time +time_increment = 100 + +# Variable to store all reads on a try +reads = {} + +print("\nInitializing test.\n") + +for milliseconds in range(min_time, max_time, time_increment): + # Instantiate the DHT11 object. + dhtDevice = adafruit_dht.DHT11(pin=getattr(board, pin_to_use)) + # Change the default wait time for triggering the read. + dhtDevice._trig_wait = milliseconds + + print(f"Using 'trig_wait' of {dhtDevice._trig_wait}") + # Reset the read count for next loop + reads_count = 0 + + # Create the key on the reads dictionary with the milliseconds used on + # this try. + if milliseconds not in reads: + reads[milliseconds] = { + "total_reads": 0 + } + + for try_number in range(0, max_retries_per_time): + try: + # Read temperature and humidity + temperature = dhtDevice.temperature + humidity = dhtDevice.humidity + read_values = { + "temperature": temperature, + "humidity": humidity + } + + if try_number not in reads[milliseconds]: + reads[milliseconds][try_number] = read_values + + reads_count += 1 + except RuntimeError as e: + time.sleep(2) + else: + time.sleep(1) + + reads[milliseconds]["total_reads"] = reads_count + + print(f"Total read(s): {reads[milliseconds]['total_reads']}\n") + dhtDevice.exit() + + +# Gather the highest read numbers from all reads done. +best_result = max( + [ + reads[milliseconds]["total_reads"] for milliseconds in reads + ] +) + +# Gather best time(s) in milliseconds where we got more reads +best_times = [ + milliseconds for milliseconds in reads if reads[milliseconds]['total_reads'] == best_result +] +print( + f"Maximum reads: {best_result} with the " + f"following times: {''.join([str(t) for t in best_times])}" +) + +# change the value on the line below to see all reads performed. +print_all = False +print(json.dumps(reads)) if print_all else None From 4de55f4bb2a7e2453fbb688444af779518198f02 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 13:39:08 +0100 Subject: [PATCH 076/153] Update dht_time_calibration.py Fix minor issue on printing best timing --- examples/dht_time_calibration.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py index a0857c4..93a6df6 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration.py @@ -76,7 +76,7 @@ ] print( f"Maximum reads: {best_result} with the " - f"following times: {''.join([str(t) for t in best_times])}" + f"following times: {' ,'.join([str(t) for t in best_times])}" ) # change the value on the line below to see all reads performed. From e62a47f410192fec0e8f2fac7ba07bfd1a1a41e2 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 13:47:09 +0100 Subject: [PATCH 077/153] Update dht_time_calibration.py Add licensing so build does not fail. --- examples/dht_time_calibration.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py index 93a6df6..3899b2e 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration.py @@ -1,3 +1,6 @@ +# SPDX-FileCopyrightText: 2021 yeyeto2788 for Adafruit Industries +# SPDX-License-Identifier: MIT + import json import time From 27909fae69d484be9e54922203ad5e71d1c099bd Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 14:16:09 +0100 Subject: [PATCH 078/153] Update dht_time_calibration.py Add more details on console output like the number of tries per trig_wait --- examples/dht_time_calibration.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py index 3899b2e..cd6c598 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration.py @@ -22,7 +22,10 @@ # Variable to store all reads on a try reads = {} -print("\nInitializing test.\n") +print( + "\nInitializing test.\n", + f"Total tries per trig_wait {max_retries_per_time}" +) for milliseconds in range(min_time, max_time, time_increment): # Instantiate the DHT11 object. @@ -78,8 +81,8 @@ milliseconds for milliseconds in reads if reads[milliseconds]['total_reads'] == best_result ] print( - f"Maximum reads: {best_result} with the " - f"following times: {' ,'.join([str(t) for t in best_times])}" + f"Maximum reads: {best_result} out of {max_retries_per_time} with the " + f"following times: {', '.join([str(t) for t in best_times])}" ) # change the value on the line below to see all reads performed. From 378d6c219c05a46590fa48b2823234b2f0194634 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 14:45:05 +0100 Subject: [PATCH 079/153] Update dht_time_calibration.py Fix issues on linting. --- examples/dht_time_calibration.py | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py index cd6c598..69540f5 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration.py @@ -8,7 +8,7 @@ import adafruit_dht -pin_to_use = 'PG6' +pin_to_use = "PG6" # Maximum number of tries per timing max_retries_per_time = 10 @@ -22,17 +22,16 @@ # Variable to store all reads on a try reads = {} -print( - "\nInitializing test.\n", - f"Total tries per trig_wait {max_retries_per_time}" -) +print("\nInitializing test.\n", f"Total tries per trig_wait {max_retries_per_time}") for milliseconds in range(min_time, max_time, time_increment): # Instantiate the DHT11 object. dhtDevice = adafruit_dht.DHT11(pin=getattr(board, pin_to_use)) # Change the default wait time for triggering the read. + # pylint: disable=W0212 dhtDevice._trig_wait = milliseconds + # pylint: disable=W0212 print(f"Using 'trig_wait' of {dhtDevice._trig_wait}") # Reset the read count for next loop reads_count = 0 @@ -40,19 +39,14 @@ # Create the key on the reads dictionary with the milliseconds used on # this try. if milliseconds not in reads: - reads[milliseconds] = { - "total_reads": 0 - } + reads[milliseconds] = {"total_reads": 0} for try_number in range(0, max_retries_per_time): try: # Read temperature and humidity temperature = dhtDevice.temperature humidity = dhtDevice.humidity - read_values = { - "temperature": temperature, - "humidity": humidity - } + read_values = {"temperature": temperature, "humidity": humidity} if try_number not in reads[milliseconds]: reads[milliseconds][try_number] = read_values @@ -68,17 +62,14 @@ print(f"Total read(s): {reads[milliseconds]['total_reads']}\n") dhtDevice.exit() - # Gather the highest read numbers from all reads done. -best_result = max( - [ - reads[milliseconds]["total_reads"] for milliseconds in reads - ] -) +best_result = max([reads[milliseconds]["total_reads"] for milliseconds in reads]) # Gather best time(s) in milliseconds where we got more reads best_times = [ - milliseconds for milliseconds in reads if reads[milliseconds]['total_reads'] == best_result + milliseconds + for milliseconds in reads + if reads[milliseconds]["total_reads"] == best_result ] print( f"Maximum reads: {best_result} out of {max_retries_per_time} with the " @@ -87,4 +78,5 @@ # change the value on the line below to see all reads performed. print_all = False -print(json.dumps(reads)) if print_all else None +if print_all: + print(json.dumps(reads)) From c1276dba59876b815686d147b4947d92e757dcbf Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Fri, 19 Mar 2021 15:24:36 +0100 Subject: [PATCH 080/153] Update dht_time_calibration.py Add more description and also what parameters were used on the test. --- examples/dht_time_calibration.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration.py index 69540f5..b603d65 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration.py @@ -12,9 +12,9 @@ # Maximum number of tries per timing max_retries_per_time = 10 -# Minimum time from where to start testing -min_time = 500 -# Maximum time on where to stop testing +# Minimum wait time from where to start testing +min_time = 1500 +# Maximum wait time on where to stop testing max_time = 2000 # Increment on time time_increment = 100 @@ -22,7 +22,20 @@ # Variable to store all reads on a try reads = {} -print("\nInitializing test.\n", f"Total tries per trig_wait {max_retries_per_time}") +initial_msg = f""" +\nInitializing test with the following parameters: + +- Maximum retries per waiting time: {max_retries_per_time} +- Start time (ms): {min_time} +- End time (ms): {max_time} +- Increment time (ms): {time_increment} + +This execution will try to read the sensor {max_retries_per_time} times +for {len(range(min_time, max_time, time_increment))} different wait times values. + +""" +# Print initial message on the console. +print(initial_msg) for milliseconds in range(min_time, max_time, time_increment): # Instantiate the DHT11 object. From ce00fb8b5199c01947e0b0ec6c3a32bec199d18e Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 19 Mar 2021 13:49:01 -0400 Subject: [PATCH 081/153] "Increase duplicate code check threshold " --- .pylintrc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.pylintrc b/.pylintrc index 89dd17d..27437ba 100644 --- a/.pylintrc +++ b/.pylintrc @@ -22,8 +22,7 @@ ignore-patterns= #init-hook= # Use multiple processes to speed up Pylint. -# jobs=1 -jobs=2 +jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. @@ -252,7 +251,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 6c9561bfaedb1cd8b1e1a2bf73f79ed4be7d38a0 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 23 Mar 2021 08:31:39 +0100 Subject: [PATCH 082/153] Add better description to advace script Add better description to the advance script. Add the `venv` folder to be ignore. Add the ussage of the script for the documentation. --- .gitignore | 1 + docs/examples.rst | 10 ++++++++++ ...ibration.py => dht_time_calibration_advance.py} | 14 ++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-) rename examples/{dht_time_calibration.py => dht_time_calibration_advance.py} (83%) diff --git a/.gitignore b/.gitignore index 9647e71..597d08d 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,4 @@ bundles .eggs dist **/*.egg-info +venv diff --git a/docs/examples.rst b/docs/examples.rst index 10e4456..96a0405 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -6,3 +6,13 @@ Ensure your device works with this simple test. .. literalinclude:: ../examples/dht_simpletest.py :caption: examples/dht_simpletest.py :linenos: + + +Time calibration advance test +------------ + +Check what is the best time your sensor. + +.. literalinclude:: ../examples/dht_time_calibration_advance.py + :caption: examples/dht_time_calibration_advance.py + :linenos: \ No newline at end of file diff --git a/examples/dht_time_calibration.py b/examples/dht_time_calibration_advance.py similarity index 83% rename from examples/dht_time_calibration.py rename to examples/dht_time_calibration_advance.py index b603d65..9879f6c 100644 --- a/examples/dht_time_calibration.py +++ b/examples/dht_time_calibration_advance.py @@ -1,6 +1,15 @@ # SPDX-FileCopyrightText: 2021 yeyeto2788 for Adafruit Industries # SPDX-License-Identifier: MIT +""" +This script let's you check the best timing for you sensor as other people have face timing issues +as seen on issue https://github.com/adafruit/Adafruit_CircuitPython_DHT/issues/66. + +By changing the variables values below you will be able to check the best timing for you sensor, +take into account that by most datasheets the timing for the sensor are 0.001 DHT22 and +0.018 for DHT11 which are the default values of the library. +""" + import json import time @@ -8,6 +17,7 @@ import adafruit_dht +# Change the pin used below pin_to_use = "PG6" # Maximum number of tries per timing @@ -41,10 +51,10 @@ # Instantiate the DHT11 object. dhtDevice = adafruit_dht.DHT11(pin=getattr(board, pin_to_use)) # Change the default wait time for triggering the read. - # pylint: disable=W0212 + # pylint: disable=protected-access dhtDevice._trig_wait = milliseconds - # pylint: disable=W0212 + # pylint: disable=protected-access print(f"Using 'trig_wait' of {dhtDevice._trig_wait}") # Reset the read count for next loop reads_count = 0 From 153f2b163a52c63703e0203921f180efb384311b Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 23 Mar 2021 10:00:06 +0100 Subject: [PATCH 083/153] Update examples.rst Add new line on file --- docs/examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples.rst b/docs/examples.rst index 96a0405..187d8ec 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -15,4 +15,4 @@ Check what is the best time your sensor. .. literalinclude:: ../examples/dht_time_calibration_advance.py :caption: examples/dht_time_calibration_advance.py - :linenos: \ No newline at end of file + :linenos: From 7afac543a4dcbf63cc6878c8e0274b4cd0745667 Mon Sep 17 00:00:00 2001 From: yeyeto2788 Date: Tue, 23 Mar 2021 13:04:38 +0100 Subject: [PATCH 084/153] Update examples.rst Add longer heading underscore line. --- docs/examples.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/examples.rst b/docs/examples.rst index 187d8ec..399b499 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -9,7 +9,7 @@ Ensure your device works with this simple test. Time calibration advance test ------------- +------------------------------ Check what is the best time your sensor. From 147d0dbec14acb87c2a3b67b28efe21b2a412d06 Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Sun, 25 Apr 2021 13:00:43 -0400 Subject: [PATCH 085/153] improving_docs --- adafruit_dht.py | 23 +++++++++++++++++++---- docs/examples.rst | 13 ++++++++++++- docs/index.rst | 2 ++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 2e76eb9..d11881b 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -9,6 +9,21 @@ CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. * Author(s): Mike McWethy + +**Hardware:** + +* Adafruit `DHT22 temperature-humidity sensor + extras + `_ (Product ID: 385) + +* Adafruit `DHT11 basic temperature-humidity sensor + extras + `_ (Product ID: 386) + + +**Software and Dependencies:** + +* Adafruit CircuitPython firmware for the supported boards: + https://circuitpython.org/downloads + """ import array @@ -92,7 +107,7 @@ def _pulses_to_binary(self, pulses, start, stop): return binary def _get_pulses_pulseio(self): - """_get_pulses implements the communication protcol for + """_get_pulses implements the communication protocol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the return signal lengths. @@ -169,7 +184,7 @@ def measure(self): if successful, the class properties temperature and humidity will return the reading returned from the device. - Raises RuntimeError exception for checksum failure and for insuffcient + Raises RuntimeError exception for checksum failure and for insufficient data returned from the device (try again) """ delay_between_readings = 2 # 2 seconds per read according to datasheet @@ -238,7 +253,7 @@ def measure(self): def temperature(self): """temperature current reading. It makes sure a reading is available - Raises RuntimeError exception for checksum failure and for insuffcient + Raises RuntimeError exception for checksum failure and for insufficient data returned from the device (try again) """ self.measure() @@ -248,7 +263,7 @@ def temperature(self): def humidity(self): """humidity current reading. It makes sure a reading is available - Raises RuntimeError exception for checksum failure and for insuffcient + Raises RuntimeError exception for checksum failure and for insufficient data returned from the device (try again) """ self.measure() diff --git a/docs/examples.rst b/docs/examples.rst index 399b499..9eaf319 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -8,10 +8,21 @@ Ensure your device works with this simple test. :linenos: +DHT to Led Display +------------------ + +Example of reading temperature and humidity from a DHT device +and displaying results to the serial port and a 8 digit 7-segment display + +.. literalinclude:: ../examples/dht_to_led_display.py + :caption: examples/dht_to_led_display.py + :linenos: + + Time calibration advance test ------------------------------ -Check what is the best time your sensor. +Example to identify best waiting time for the sensor .. literalinclude:: ../examples/dht_time_calibration_advance.py :caption: examples/dht_time_calibration_advance.py diff --git a/docs/index.rst b/docs/index.rst index 2c9e99b..76d6e64 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + DHT basic temperature-humidity sensor Learning Guide + .. toctree:: :caption: Related Products From a6733e575e2d95a1f98deac7ea950bc72635e03e Mon Sep 17 00:00:00 2001 From: jposada202020 Date: Mon, 26 Apr 2021 16:56:29 -0400 Subject: [PATCH 086/153] Changing README.rst. to address know issues and product support --- README.rst | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 1e4513e..6dda3a1 100644 --- a/README.rst +++ b/README.rst @@ -58,9 +58,26 @@ Usage Example Hardware Set-up ---------------- -The DHT11 and DHT22 devices both need a pull-resistor on the data signal wire. -This resistor is in the range of 1k to 5k. Please check your device datasheet for the -appropriate value. +Designed specifically to work with the Adafruit DHT series sensors: + +* Adafruit `DHT22 temperature-humidity sensor + extras `_ +* Adafruit `DHT11 temperature-humidity sensor + extras `_ + +.. note:: + DHT11 and DHT22 devices both need a pull-resistor on the data signal wire. This resistor is in the range of 1k to 5k + + +* Please check the device datasheet for the appropriate value. +* Be sure that you are running Buster Operating System. +* Make sure that your user is part of the ``gpio`` group. + + +Known Issues +------------ + +* Library may or may not work in Linux 64-bit platforms +* Raspberry PI-ZERO does not provide reliable readings +* Readings in FeatherS2 does not work as expected. Basics ------- From 01b104c8923169861e88688c6840c0351c572ef4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:32:42 -0400 Subject: [PATCH 087/153] Added pull request template Signed-off-by: dherrada --- .../adafruit_circuitpython_pr.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md new file mode 100644 index 0000000..71ef8f8 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -0,0 +1,13 @@ +# SPDX-FileCopyrightText: 2021 Adafruit Industries +# +# SPDX-License-Identifier: MIT + +Thank you for contributing! Before you submit a pull request, please read the following. + +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html + +If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs + +Before submitting the pull request, make sure you've run Pylint and Black locally on your code. You can do this manually or using pre-commit. Instructions are available here: https://adafru.it/check-your-code + +Please remove all of this text before submitting. Include an explanation or list of changes included in your PR, as well as, if applicable, a link to any related issues. From 314e38ff9496e948d7a181e21022cda2e2d033f6 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 19 May 2021 13:35:18 -0400 Subject: [PATCH 088/153] Added help text and problem matcher Signed-off-by: dherrada --- .github/workflows/build.yml | 2 ++ .github/workflows/failure-help-text.yml | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .github/workflows/failure-help-text.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3baf502..0ab7182 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,3 +71,5 @@ jobs: python setup.py sdist python setup.py bdist_wheel --universal twine check dist/* + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/failure-help-text.yml b/.github/workflows/failure-help-text.yml new file mode 100644 index 0000000..0b1194f --- /dev/null +++ b/.github/workflows/failure-help-text.yml @@ -0,0 +1,19 @@ +# SPDX-FileCopyrightText: 2021 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Failure help text + +on: + workflow_run: + workflows: ["Build CI"] + types: + - completed + +jobs: + post-help: + runs-on: ubuntu-latest + if: ${{ github.event.workflow_run.conclusion == 'failure' && github.event.workflow_run.event == 'pull_request' }} + steps: + - name: Post comment to help + uses: adafruit/circuitpython-action-library-ci-failed@v1 From dbec944490a25d6cdb567fb2df7add10a5e1c9b4 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 May 2021 09:54:31 -0400 Subject: [PATCH 089/153] Moved CI to Python 3.7 Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 0ab7182..c4c975d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 + - name: Set up Python 3.7 uses: actions/setup-python@v1 with: - python-version: 3.6 + python-version: 3.7 - name: Versions run: | python3 --version From 6bb55076631a1f13a8c05595529f0b3a442347fd Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 7 Jun 2021 12:37:54 -0400 Subject: [PATCH 090/153] Moved default branch to main --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 6dda3a1..fcb7bb3 100644 --- a/README.rst +++ b/README.rst @@ -124,7 +124,7 @@ Contributing ============ Contributions are welcome! Please read our `Code of Conduct -`_ +`_ before contributing to help this project stay welcoming. Documentation From 5b3fa789ce71c1797e8d3590c7761f02d969ab04 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 23 Sep 2021 17:52:55 -0400 Subject: [PATCH 091/153] Globally disabled consider-using-f-string pylint check Signed-off-by: dherrada --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From 81ee53812287d4b2ea0da0c1521f6d5335aa2724 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 27 Sep 2021 15:47:13 -0400 Subject: [PATCH 092/153] Linted --- examples/dht_time_calibration_advance.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index 9879f6c..5c8ed58 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -86,12 +86,13 @@ dhtDevice.exit() # Gather the highest read numbers from all reads done. -best_result = max([reads[milliseconds]["total_reads"] for milliseconds in reads]) - +best_result = max( + [reads[milliseconds]["total_reads"] for milliseconds in reads] # pylint: disable=consider-using-dict-items +) # Gather best time(s) in milliseconds where we got more reads best_times = [ milliseconds - for milliseconds in reads + for milliseconds in reads # pylint: disable=consider-using-dict-items if reads[milliseconds]["total_reads"] == best_result ] print( From dc96caa47879be59524af22d5b755c0302b6304a Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Sep 2021 12:37:55 -0400 Subject: [PATCH 093/153] Fixed linting --- examples/dht_time_calibration_advance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index 9879f6c..88d81cd 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -91,8 +91,8 @@ # Gather best time(s) in milliseconds where we got more reads best_times = [ milliseconds - for milliseconds in reads - if reads[milliseconds]["total_reads"] == best_result + for milliseconds in reads.values() + if milliseconds["total_reads"] == best_result ] print( f"Maximum reads: {best_result} out of {max_retries_per_time} with the " From 0987c3323be166aa075ddc48b4adb933a742aeba Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Sep 2021 12:46:35 -0400 Subject: [PATCH 094/153] Revert "Globally disabled consider-using-f-string pylint check" This reverts commit 5b3fa789ce71c1797e8d3590c7761f02d969ab04. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..354c761 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] language: system From 0fbed94e8f4776a574136945396f003b49c12aab Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Sep 2021 12:47:20 -0400 Subject: [PATCH 095/153] Revert "Fixed linting" This reverts commit dc96caa47879be59524af22d5b755c0302b6304a. --- examples/dht_time_calibration_advance.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index 88d81cd..9879f6c 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -91,8 +91,8 @@ # Gather best time(s) in milliseconds where we got more reads best_times = [ milliseconds - for milliseconds in reads.values() - if milliseconds["total_reads"] == best_result + for milliseconds in reads + if reads[milliseconds]["total_reads"] == best_result ] print( f"Maximum reads: {best_result} out of {max_retries_per_time} with the " From 93cd1e096f2a501fa26120a72250c3a59de3f3b2 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Sep 2021 12:47:52 -0400 Subject: [PATCH 096/153] Revert "Revert "Globally disabled consider-using-f-string pylint check"" This reverts commit 0987c3323be166aa075ddc48b4adb933a742aeba. --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 354c761..8810708 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -30,5 +30,5 @@ repos: name: pylint (examples code) description: Run pylint rules on "examples/*.py" files entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name $example; done)'] + args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] language: system From b72300d69bc7c90744028288c7011aa2698b1c94 Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 28 Sep 2021 13:02:14 -0400 Subject: [PATCH 097/153] Fixed linting --- examples/dht_time_calibration_advance.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index 5c8ed58..d60b7ac 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -87,7 +87,10 @@ # Gather the highest read numbers from all reads done. best_result = max( - [reads[milliseconds]["total_reads"] for milliseconds in reads] # pylint: disable=consider-using-dict-items + [ + reads[milliseconds]["total_reads"] + for milliseconds in reads # pylint: disable=consider-using-dict-items + ] ) # Gather best time(s) in milliseconds where we got more reads best_times = [ From a1e05a0edee7d9a214574649dedb1562fc1946a2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 25 Oct 2021 11:14:40 -0500 Subject: [PATCH 098/153] add docs link to readme --- README.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.rst b/README.rst index fcb7bb3..d505372 100644 --- a/README.rst +++ b/README.rst @@ -120,6 +120,11 @@ These properties may raise an exception if a problem occurs. You should use try logic and catch RuntimeError and then retry getting the values after at least 2 seconds. If you try again to get a result within 2 seconds, cached values are returned. +Documentation +============= + +API documentation for this library can be found on `Read the Docs `_. + Contributing ============ From 24a4c6c0e491c97d7f16e61ccea395343e848bbc Mon Sep 17 00:00:00 2001 From: Tyler Crumpton Date: Sun, 31 Oct 2021 16:58:53 -0500 Subject: [PATCH 099/153] Add type hints --- adafruit_dht.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index d11881b..8a34d93 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -30,6 +30,7 @@ import time from os import uname from digitalio import DigitalInOut, Pull, Direction +from microcontroller import Pin _USE_PULSEIO = False try: @@ -49,7 +50,7 @@ class DHTBase: __hiLevel = 51 - def __init__(self, dht11, pin, trig_wait, use_pulseio): + def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): """ :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication @@ -59,25 +60,25 @@ def __init__(self, dht11, pin, trig_wait, use_pulseio): self._dht11 = dht11 self._pin = pin self._trig_wait = trig_wait - self._last_called = 0 - self._humidity = None - self._temperature = None + self._last_called: float = 0 + self._humidity: int | float | None = None + self._temperature: int | float | None = None self._use_pulseio = use_pulseio if "Linux" not in uname() and not self._use_pulseio: raise Exception("Bitbanging is not supported when using CircuitPython.") # We don't use a context because linux-based systems are sluggish # and we're better off having a running process if self._use_pulseio: - self.pulse_in = PulseIn(self._pin, 81, True) + self.pulse_in = PulseIn(self._pin, maxlen=81, idle_state=True) self.pulse_in.pause() - def exit(self): - """ Cleans up the PulseIn process. Must be called explicitly """ + def exit(self) -> None: + """Cleans up the PulseIn process. Must be called explicitly""" if self._use_pulseio: print("De-initializing self.pulse_in") self.pulse_in.deinit() - def _pulses_to_binary(self, pulses, start, stop): + def _pulses_to_binary(self, pulses: array.array[int], start: int, stop: int) -> int: """Takes pulses, a list of transition times, and converts them to a 1's or 0's. The pulses array contains the transition times. pulses starts with a low transition time followed by a high transistion time. @@ -106,7 +107,7 @@ def _pulses_to_binary(self, pulses, start, stop): return binary - def _get_pulses_pulseio(self): + def _get_pulses_pulseio(self) -> array.array[int]: """_get_pulses implements the communication protocol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the @@ -134,7 +135,7 @@ def _get_pulses_pulseio(self): pulses.append(self.pulse_in.popleft()) return pulses - def _get_pulses_bitbang(self): + def _get_pulses_bitbang(self) -> array.array[int]: """_get_pulses implements the communication protcol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the @@ -179,7 +180,7 @@ def _get_pulses_bitbang(self): pulses.append(min(pulses_micro_sec, 65535)) return pulses - def measure(self): + def measure(self) -> None: """measure runs the communications to the DHT11/22 type device. if successful, the class properties temperature and humidity will return the reading returned from the device. @@ -197,8 +198,8 @@ def measure(self): ): self._last_called = time.monotonic() - new_temperature = 0 - new_humidity = 0 + new_temperature: int | float = 0 + new_humidity: int | float = 0 if self._use_pulseio: pulses = self._get_pulses_pulseio() @@ -250,7 +251,7 @@ def measure(self): self._humidity = new_humidity @property - def temperature(self): + def temperature(self) -> int | float | None: """temperature current reading. It makes sure a reading is available Raises RuntimeError exception for checksum failure and for insufficient @@ -260,7 +261,7 @@ def temperature(self): return self._temperature @property - def humidity(self): + def humidity(self) -> int | float | None: """humidity current reading. It makes sure a reading is available Raises RuntimeError exception for checksum failure and for insufficient @@ -276,7 +277,7 @@ class DHT11(DHTBase): :param ~board.Pin pin: digital pin used for communication """ - def __init__(self, pin, use_pulseio=_USE_PULSEIO): + def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): super().__init__(True, pin, 18000, use_pulseio) @@ -286,5 +287,5 @@ class DHT22(DHTBase): :param ~board.Pin pin: digital pin used for communication """ - def __init__(self, pin, use_pulseio=_USE_PULSEIO): + def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): super().__init__(False, pin, 1000, use_pulseio) From f88349e02ef537ad63c53e304b6b9d21c333deb0 Mon Sep 17 00:00:00 2001 From: Tyler Crumpton Date: Sun, 31 Oct 2021 17:11:26 -0500 Subject: [PATCH 100/153] Fix Union types --- adafruit_dht.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 8a34d93..b0ffecf 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -30,7 +30,6 @@ import time from os import uname from digitalio import DigitalInOut, Pull, Direction -from microcontroller import Pin _USE_PULSEIO = False try: @@ -40,6 +39,12 @@ except (ImportError, NotImplementedError): pass # This is OK, we'll try to bitbang it! +try: + # Used only for typing + from typing import Union + from microcontroller import Pin +except ImportError: + pass __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git" @@ -61,8 +66,8 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): self._pin = pin self._trig_wait = trig_wait self._last_called: float = 0 - self._humidity: int | float | None = None - self._temperature: int | float | None = None + self._humidity: Union[int, float, None] = None + self._temperature: Union[int, float, None] = None self._use_pulseio = use_pulseio if "Linux" not in uname() and not self._use_pulseio: raise Exception("Bitbanging is not supported when using CircuitPython.") @@ -198,8 +203,8 @@ def measure(self) -> None: ): self._last_called = time.monotonic() - new_temperature: int | float = 0 - new_humidity: int | float = 0 + new_temperature: Union[int, float] = 0 + new_humidity: Union[int, float] = 0 if self._use_pulseio: pulses = self._get_pulses_pulseio() @@ -251,7 +256,7 @@ def measure(self) -> None: self._humidity = new_humidity @property - def temperature(self) -> int | float | None: + def temperature(self) -> Union[int, float, None]: """temperature current reading. It makes sure a reading is available Raises RuntimeError exception for checksum failure and for insufficient @@ -261,7 +266,7 @@ def temperature(self) -> int | float | None: return self._temperature @property - def humidity(self) -> int | float | None: + def humidity(self) -> Union[int, float, None]: """humidity current reading. It makes sure a reading is available Raises RuntimeError exception for checksum failure and for insufficient From a6e68f3ffb8d53f6c86ad7a6ccf1ee66a9154b81 Mon Sep 17 00:00:00 2001 From: Tyler Crumpton Date: Sun, 31 Oct 2021 17:19:17 -0500 Subject: [PATCH 101/153] Remove variable types --- adafruit_dht.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index b0ffecf..44a4aab 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -65,9 +65,9 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): self._dht11 = dht11 self._pin = pin self._trig_wait = trig_wait - self._last_called: float = 0 - self._humidity: Union[int, float, None] = None - self._temperature: Union[int, float, None] = None + self._last_called = 0 + self._humidity = None + self._temperature = None self._use_pulseio = use_pulseio if "Linux" not in uname() and not self._use_pulseio: raise Exception("Bitbanging is not supported when using CircuitPython.") @@ -203,8 +203,8 @@ def measure(self) -> None: ): self._last_called = time.monotonic() - new_temperature: Union[int, float] = 0 - new_humidity: Union[int, float] = 0 + new_temperature = 0 + new_humidity = 0 if self._use_pulseio: pulses = self._get_pulses_pulseio() From ebe3bbc3a7b9fbcfd9046823138789260bda192c Mon Sep 17 00:00:00 2001 From: Tyler Crumpton Date: Sun, 31 Oct 2021 17:44:01 -0500 Subject: [PATCH 102/153] Fix unhappy array typing --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 44a4aab..73d53bc 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -112,7 +112,7 @@ def _pulses_to_binary(self, pulses: array.array[int], start: int, stop: int) -> return binary - def _get_pulses_pulseio(self) -> array.array[int]: + def _get_pulses_pulseio(self) -> array.array: """_get_pulses implements the communication protocol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the From 0b71c903a065d28b4c9f2301e1089b9463e12dcd Mon Sep 17 00:00:00 2001 From: Tyler Crumpton Date: Sun, 31 Oct 2021 17:50:16 -0500 Subject: [PATCH 103/153] Fix other array type hints --- adafruit_dht.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 73d53bc..bdef594 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -83,7 +83,7 @@ def exit(self) -> None: print("De-initializing self.pulse_in") self.pulse_in.deinit() - def _pulses_to_binary(self, pulses: array.array[int], start: int, stop: int) -> int: + def _pulses_to_binary(self, pulses: array.array, start: int, stop: int) -> int: """Takes pulses, a list of transition times, and converts them to a 1's or 0's. The pulses array contains the transition times. pulses starts with a low transition time followed by a high transistion time. @@ -140,7 +140,7 @@ def _get_pulses_pulseio(self) -> array.array: pulses.append(self.pulse_in.popleft()) return pulses - def _get_pulses_bitbang(self) -> array.array[int]: + def _get_pulses_bitbang(self) -> array.array: """_get_pulses implements the communication protcol for DHT11 and DHT22 type devices. It sends a start signal of a specific length and listens and measures the From 355aec1c0c81e1d29b65194454eec7417e0e0849 Mon Sep 17 00:00:00 2001 From: dherrada Date: Wed, 3 Nov 2021 14:40:16 -0400 Subject: [PATCH 104/153] PATCH Pylint and readthedocs patch test Signed-off-by: dherrada --- .github/workflows/build.yml | 4 ++-- .pre-commit-config.yaml | 26 +++++++++++++++++--------- .pylintrc | 2 +- .readthedocs.yml | 2 +- docs/requirements.txt | 5 +++++ 5 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 docs/requirements.txt diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c4c975d..ca35544 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,9 +42,9 @@ jobs: # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) run: | source actions-ci/install.sh - - name: Pip install pylint, Sphinx, pre-commit + - name: Pip install Sphinx, pre-commit run: | - pip install --force-reinstall pylint Sphinx sphinx-rtd-theme pre-commit + pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags - name: Pre-commit hooks diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8810708..1b9fadc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,17 +18,25 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: pylint-2.7.1 + rev: v2.11.1 hooks: - id: pylint name: pylint (library code) types: [python] - exclude: "^(docs/|examples/|setup.py$)" -- repo: local - hooks: - - id: pylint_examples - name: pylint (examples code) + args: + - --disable=consider-using-f-string + exclude: "^(docs/|examples/|tests/|setup.py$)" + - id: pylint + name: pylint (example code) description: Run pylint rules on "examples/*.py" files - entry: /usr/bin/env bash -c - args: ['([[ ! -d "examples" ]] || for example in $(find . -path "./examples/*.py"); do pylint --disable=missing-docstring,invalid-name,consider-using-f-string $example; done)'] - language: system + types: [python] + files: "^examples/" + args: + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint + name: pylint (test code) + description: Run pylint rules on "tests/*.py" files + types: [python] + files: "^tests/" + args: + - --disable=missing-docstring,consider-using-f-string,duplicate-code diff --git a/.pylintrc b/.pylintrc index 27437ba..fa47a7c 100644 --- a/.pylintrc +++ b/.pylintrc @@ -251,7 +251,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=12 +min-similarity-lines=4 [BASIC] diff --git a/.readthedocs.yml b/.readthedocs.yml index ffa84c4..49dcab3 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -4,4 +4,4 @@ python: version: 3 -requirements_file: requirements.txt +requirements_file: docs/requirements.txt diff --git a/docs/requirements.txt b/docs/requirements.txt new file mode 100644 index 0000000..88e6733 --- /dev/null +++ b/docs/requirements.txt @@ -0,0 +1,5 @@ +# SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +sphinx>=4.0.0 From 6dd3ddc3b0b655bf2a059f85e39fa05089e11851 Mon Sep 17 00:00:00 2001 From: dherrada Date: Fri, 5 Nov 2021 14:49:30 -0400 Subject: [PATCH 105/153] Disabled unspecified-encoding pylint check Signed-off-by: dherrada --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index fa47a7c..f0c8611 100644 --- a/.pylintrc +++ b/.pylintrc @@ -55,7 +55,7 @@ confidence= # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" # disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation +disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option From 244a7d1f0da8da57bd167a52867c4bf9d1cfe1fc Mon Sep 17 00:00:00 2001 From: dherrada Date: Tue, 9 Nov 2021 13:31:14 -0500 Subject: [PATCH 106/153] Updated readthedocs file Signed-off-by: dherrada --- .readthedocs.yaml | 15 +++++++++++++++ .readthedocs.yml | 7 ------- 2 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 .readthedocs.yaml delete mode 100644 .readthedocs.yml diff --git a/.readthedocs.yaml b/.readthedocs.yaml new file mode 100644 index 0000000..95ec218 --- /dev/null +++ b/.readthedocs.yaml @@ -0,0 +1,15 @@ +# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +# Read the Docs configuration file +# See https://docs.readthedocs.io/en/stable/config-file/v2.html for details + +# Required +version: 2 + +python: + version: "3.6" + install: + - requirements: docs/requirements.txt + - requirements: requirements.txt diff --git a/.readthedocs.yml b/.readthedocs.yml deleted file mode 100644 index 49dcab3..0000000 --- a/.readthedocs.yml +++ /dev/null @@ -1,7 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -python: - version: 3 -requirements_file: docs/requirements.txt From 5c287a2a3aaa23c8d38d733f7392a5c1dadf3485 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Wed, 17 Nov 2021 10:55:57 +0100 Subject: [PATCH 107/153] Support for DHT21/AM2301 --- adafruit_dht.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index bdef594..3ebabf7 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -55,7 +55,7 @@ class DHTBase: __hiLevel = 51 - def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): + def __init__(self, dht11: bool, pin: Pin, trig_wait: int, max_pulses: int, use_pulseio: bool): """ :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication @@ -65,6 +65,7 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): self._dht11 = dht11 self._pin = pin self._trig_wait = trig_wait + self._max_pulses = max_pulses self._last_called = 0 self._humidity = None self._temperature = None @@ -74,7 +75,7 @@ def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool): # We don't use a context because linux-based systems are sluggish # and we're better off having a running process if self._use_pulseio: - self.pulse_in = PulseIn(self._pin, maxlen=81, idle_state=True) + self.pulse_in = PulseIn(self._pin, maxlen=self._max_pulses, idle_state=True) self.pulse_in.pause() def exit(self) -> None: @@ -179,7 +180,7 @@ def _get_pulses_bitbang(self) -> array.array: transitions.append(time.monotonic()) # save the timestamp # convert transtions to microsecond delta pulses: # use last 81 pulses - transition_start = max(1, len(transitions) - 81) + transition_start = max(1, len(transitions) - self._max_pulses) for i in range(transition_start, len(transitions)): pulses_micro_sec = int(1000000 * (transitions[i] - transitions[i - 1])) pulses.append(min(pulses_micro_sec, 65535)) @@ -283,7 +284,7 @@ class DHT11(DHTBase): """ def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): - super().__init__(True, pin, 18000, use_pulseio) + super().__init__(True, pin, 18000, 81, use_pulseio) class DHT22(DHTBase): @@ -293,4 +294,18 @@ class DHT22(DHTBase): """ def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): - super().__init__(False, pin, 1000, use_pulseio) + super().__init__(False, pin, 1000, 81, use_pulseio) + + +class DHT21(DHTBase): + """Support for DHT21/AM2301 device. + + :param ~board.Pin pin: digital pin used for communication + """ + + # DHT21/AM2301 is sending three more dummy bytes after the "official" protocol. + # Pulseio will take only the last pulses up to maxPulses. + # If that would be 81, the dummy pulses will be read and the real data would be truncated. + # Hence setting maxPulses to 129, taking both real data and dummy bytes into buffer. + def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): + super().__init__(False, pin, 1000, 129, use_pulseio) From c841a69d275bb386d0b2417acb3e3ec3f5e181bb Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Thu, 18 Nov 2021 17:49:31 +0100 Subject: [PATCH 108/153] Making pylint happy Co-authored-by: Scott Shawcroft --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 3ebabf7..085ab09 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -55,7 +55,7 @@ class DHTBase: __hiLevel = 51 - def __init__(self, dht11: bool, pin: Pin, trig_wait: int, max_pulses: int, use_pulseio: bool): + def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool, *, max_pulses: int = 81): """ :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication From 88569bb37510c9c2eef68ad21fe8e8584ff4d1e7 Mon Sep 17 00:00:00 2001 From: Radovan Semancik Date: Thu, 18 Nov 2021 20:00:20 +0100 Subject: [PATCH 109/153] Making pylint really happy --- adafruit_dht.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 085ab09..cd998dc 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -55,7 +55,15 @@ class DHTBase: __hiLevel = 51 - def __init__(self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool, *, max_pulses: int = 81): + def __init__( + self, + dht11: bool, + pin: Pin, + trig_wait: int, + use_pulseio: bool, + *, + max_pulses: int = 81 + ): """ :param boolean dht11: True if device is DHT11, otherwise DHT22. :param ~board.Pin pin: digital pin used for communication @@ -284,7 +292,7 @@ class DHT11(DHTBase): """ def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): - super().__init__(True, pin, 18000, 81, use_pulseio) + super().__init__(True, pin, 18000, use_pulseio) class DHT22(DHTBase): @@ -294,7 +302,7 @@ class DHT22(DHTBase): """ def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): - super().__init__(False, pin, 1000, 81, use_pulseio) + super().__init__(False, pin, 1000, use_pulseio) class DHT21(DHTBase): @@ -308,4 +316,4 @@ class DHT21(DHTBase): # If that would be 81, the dummy pulses will be read and the real data would be truncated. # Hence setting maxPulses to 129, taking both real data and dummy bytes into buffer. def __init__(self, pin: Pin, use_pulseio: bool = _USE_PULSEIO): - super().__init__(False, pin, 1000, 129, use_pulseio) + super().__init__(False, pin, 1000, use_pulseio, max_pulses=129) From 81e41138e6377fdafa81bc36a5be2c4cd50a3359 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 23 Nov 2021 13:00:26 -0600 Subject: [PATCH 110/153] update rtd py version --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 95ec218..1335112 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.6" + version: "3.7" install: - requirements: docs/requirements.txt - requirements: requirements.txt From bb68fba559be318729761627f52519be0b5fe6e9 Mon Sep 17 00:00:00 2001 From: Dan Halbert Date: Fri, 3 Dec 2021 19:20:05 -0500 Subject: [PATCH 111/153] no pulseio on certain boards; recommend modern sensors --- README.rst | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index d505372..d283db3 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,15 @@ Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading `the Adafruit library and driver bundle `_. +.. note:: + This library uses the `pulseio` module in CircuitPython. As of CircuitPython 7.0.0, `pulseio` is + no longer available on the smallest CircuitPython builds, + such as the Trinket M0, Gemma M0, and Feather M0 Basic boards. + You can substitute a more modern sensor, which will work better as well. + See the guide `Modern Replacements for DHT11 and DHT22 Sensors + `_ + for suggestions. + Installing from PyPI ==================== @@ -68,17 +77,22 @@ Designed specifically to work with the Adafruit DHT series sensors: * Please check the device datasheet for the appropriate value. -* Be sure that you are running Buster Operating System. +* Be sure that you are running the Buster Operating System. * Make sure that your user is part of the ``gpio`` group. Known Issues ------------ -* Library may or may not work in Linux 64-bit platforms -* Raspberry PI-ZERO does not provide reliable readings +* The library may or may not work in Linux 64-bit platforms. +* The Raspberry PI Zero does not provide reliable readings. * Readings in FeatherS2 does not work as expected. +.. note:: + Using a more modern sensor will avoid these issues. + See the guide `Modern Replacements for DHT11 and DHT22 Sensors + `_. + Basics ------- From 95db6ff282b739e5a94c5482778dd0258ab984f5 Mon Sep 17 00:00:00 2001 From: dherrada Date: Thu, 13 Jan 2022 16:27:30 -0500 Subject: [PATCH 112/153] First part of patch Signed-off-by: dherrada --- .../PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md | 2 +- .github/workflows/build.yml | 6 +++--- .github/workflows/release.yml | 8 ++++---- .readthedocs.yaml | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md index 71ef8f8..8de294e 100644 --- a/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md +++ b/.github/PULL_REQUEST_TEMPLATE/adafruit_circuitpython_pr.md @@ -4,7 +4,7 @@ Thank you for contributing! Before you submit a pull request, please read the following. -Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://circuitpython.readthedocs.io/en/latest/docs/design_guide.html +Make sure any changes you're submitting are in line with the CircuitPython Design Guide, available here: https://docs.circuitpython.org/en/latest/docs/design_guide.html If your changes are to documentation, please verify that the documentation builds locally by following the steps found here: https://adafru.it/build-docs diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ca35544..474520d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,10 +22,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.7 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.x" - name: Versions run: | python3 --version diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 6d0015a..a65e5de 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -24,10 +24,10 @@ jobs: awk -F '\/' '{ print tolower($2) }' | tr '_' '-' ) - - name: Set up Python 3.6 - uses: actions/setup-python@v1 + - name: Set up Python 3.x + uses: actions/setup-python@v2 with: - python-version: 3.6 + python-version: "3.x" - name: Versions run: | python3 --version @@ -67,7 +67,7 @@ jobs: echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) - name: Set up Python if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') - uses: actions/setup-python@v1 + uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 1335112..f8b2891 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -9,7 +9,7 @@ version: 2 python: - version: "3.7" + version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From a951fe0b87786c51b4577e4c90b1430f28039cf3 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 24 Jan 2022 16:46:16 -0500 Subject: [PATCH 113/153] Updated docs link, updated python docs link, updated setup.py --- README.rst | 4 ++-- docs/conf.py | 8 ++++---- docs/index.rst | 2 +- setup.py | 2 -- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/README.rst b/README.rst index d283db3..1abfadd 100644 --- a/README.rst +++ b/README.rst @@ -3,7 +3,7 @@ Introduction ============ .. image:: https://readthedocs.org/projects/adafruit-circuitpython-dht/badge/?version=latest - :target: https://circuitpython.readthedocs.io/projects/dht/en/latest/ + :target: https://docs.circuitpython.org/projects/dht/en/latest/ :alt: Documentation Status @@ -137,7 +137,7 @@ If you try again to get a result within 2 seconds, cached values are returned. Documentation ============= -API documentation for this library can be found on `Read the Docs `_. +API documentation for this library can be found on `Read the Docs `_. Contributing ============ diff --git a/docs/conf.py b/docs/conf.py index 379eb5f..1463aeb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -23,16 +23,16 @@ autodoc_mock_imports = ["pulseio"] intersphinx_mapping = { - "python": ("https://docs.python.org/3.4", None), + "python": ("https://docs.python.org/3", None), "BusDevice": ( - "https://circuitpython.readthedocs.io/projects/busdevice/en/latest/", + "https://docs.circuitpython.org/projects/busdevice/en/latest/", None, ), "Register": ( - "https://circuitpython.readthedocs.io/projects/register/en/latest/", + "https://docs.circuitpython.org/projects/register/en/latest/", None, ), - "CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None), + "CircuitPython": ("https://docs.circuitpython.org/en/latest/", None), } # Add any paths that contain templates here, relative to this directory. diff --git a/docs/index.rst b/docs/index.rst index 76d6e64..d33ad8e 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -36,7 +36,7 @@ Table of Contents :caption: Other Links Download - CircuitPython Reference Documentation + CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat Adafruit Learning System diff --git a/setup.py b/setup.py index a6cc107..1689b64 100644 --- a/setup.py +++ b/setup.py @@ -45,8 +45,6 @@ "Topic :: System :: Hardware", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.4", - "Programming Language :: Python :: 3.5", ], # What does your project relate to? keywords="adafruit dht hardware sensors temperature humidity micropython circuitpython", From a1e39a70c75bcadf62fbe3450eef2c3575364596 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Wed, 9 Feb 2022 12:49:12 -0500 Subject: [PATCH 114/153] Consolidate Documentation sections of README --- README.rst | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 1abfadd..59a55cb 100644 --- a/README.rst +++ b/README.rst @@ -139,14 +139,11 @@ Documentation API documentation for this library can be found on `Read the Docs `_. +For information on building library documentation, please check out `this guide `_. + Contributing ============ Contributions are welcome! Please read our `Code of Conduct `_ before contributing to help this project stay welcoming. - -Documentation -============= - -For information on building library documentation, please check out `this guide `_. From c5ce95da1c9fed67ede3af87c36547f68a13bb37 Mon Sep 17 00:00:00 2001 From: dherrada Date: Mon, 14 Feb 2022 15:35:02 -0500 Subject: [PATCH 115/153] Fixed readthedocs build Signed-off-by: dherrada --- .readthedocs.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index f8b2891..33c2a61 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,8 +8,12 @@ # Required version: 2 +build: + os: ubuntu-20.04 + tools: + python: "3" + python: - version: "3.x" install: - requirements: docs/requirements.txt - requirements: requirements.txt From 47fcaf53599a524b0621fca4bf2ee785058654d7 Mon Sep 17 00:00:00 2001 From: Neradoc Date: Mon, 28 Mar 2022 16:59:55 +0200 Subject: [PATCH 116/153] Fix documentation --- adafruit_dht.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index cd998dc..6653c83 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -51,7 +51,13 @@ class DHTBase: - """base support for DHT11 and DHT22 devices""" + """base support for DHT11 and DHT22 devices + + :param bool dht11: True if device is DHT11, otherwise DHT22. + :param ~board.Pin pin: digital pin used for communication + :param int trig_wait: length of time to hold trigger in LOW state (microseconds) + :param bool use_pulseio: False to force bitbang when pulseio available (only with Blinka) + """ __hiLevel = 51 @@ -64,12 +70,6 @@ def __init__( *, max_pulses: int = 81 ): - """ - :param boolean dht11: True if device is DHT11, otherwise DHT22. - :param ~board.Pin pin: digital pin used for communication - :param int trig_wait: length of time to hold trigger in LOW state (microseconds) - :param boolean use_pulseio: False to force bitbang when pulseio available (only with Blinka) - """ self._dht11 = dht11 self._pin = pin self._trig_wait = trig_wait From aa50ab0a2fa6cb257ef57318772271da6a896f60 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Mon, 28 Mar 2022 15:52:04 -0400 Subject: [PATCH 117/153] Update Black to latest. Signed-off-by: Kattni Rembor --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1b9fadc..7467c1d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,7 +4,7 @@ repos: - repo: https://github.com/python/black - rev: 20.8b1 + rev: 22.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool From 3fcb5ba069b2fba2176251f08028c1ce55154bf6 Mon Sep 17 00:00:00 2001 From: Eva Herrada <33632497+evaherrada@users.noreply.github.com> Date: Thu, 21 Apr 2022 18:50:03 -0400 Subject: [PATCH 118/153] Update .gitignore --- .gitignore | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 597d08d..544ec4a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,47 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries # -# SPDX-License-Identifier: Unlicense +# SPDX-License-Identifier: MIT +# Do not include files and directories created by your personal work environment, such as the IDE +# you use, except for those already listed here. Pull requests including changes to this file will +# not be accepted. + +# This .gitignore file contains rules for files generated by working with CircuitPython libraries, +# including building Sphinx, testing with pip, and creating a virual environment, as well as the +# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs. + +# If you find that there are files being generated on your machine that should not be included in +# your git commit, you should create a .gitignore_global file on your computer to include the +# files created by your personal setup. To do so, follow the two steps below. + +# First, create a file called .gitignore_global somewhere convenient for you, and add rules for +# the files you want to exclude from git commits. + +# Second, configure Git to use the exclude file for all Git repositories by running the +# following via commandline, replacing "path/to/your/" with the actual path to your newly created +# .gitignore_global file: +# git config --global core.excludesfile path/to/your/.gitignore_global + +# CircuitPython-specific files *.mpy -.idea + +# Python-specific files __pycache__ -_build *.pyc + +# Sphinx build-specific files +_build + +# This file results from running `pip -e install .` in a local repository +*.egg-info + +# Virtual environment-specific files .env -bundles + +# MacOS-specific files *.DS_Store -.eggs -dist -**/*.egg-info -venv + +# IDE-specific files +.idea +.vscode +*~ From 72b76147a9877320a44dc71c63edf2168621864d Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Apr 2022 15:58:33 -0400 Subject: [PATCH 119/153] Patch: Replaced discord badge image --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 59a55cb..f3023f6 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :alt: Documentation Status -.. image :: https://img.shields.io/discord/327254708534116352.svg +.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 3e9ef7b74c8dfab3743956de2ecb4824410ae6f3 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Sun, 24 Apr 2022 13:50:20 -0500 Subject: [PATCH 120/153] change discord badge --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f3023f6..2d7ed92 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ Introduction :alt: Documentation Status -.. image:: https://github.com/adafruit/Adafruit_CircuitPython_Bundle/blob/main/badges/adafruit_discord.svg +.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg :target: https://adafru.it/discord :alt: Discord From 561e624147a638975752eb352499ef88d7266530 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 15 May 2022 12:20:19 -0400 Subject: [PATCH 121/153] Patch .pre-commit-config.yaml --- .pre-commit-config.yaml | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7467c1d..3343606 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,40 +3,40 @@ # SPDX-License-Identifier: Unlicense repos: -- repo: https://github.com/python/black + - repo: https://github.com/python/black rev: 22.3.0 hooks: - - id: black -- repo: https://github.com/fsfe/reuse-tool - rev: v0.12.1 + - id: black + - repo: https://github.com/fsfe/reuse-tool + rev: v0.14.0 hooks: - - id: reuse -- repo: https://github.com/pre-commit/pre-commit-hooks - rev: v2.3.0 + - id: reuse + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.2.0 hooks: - - id: check-yaml - - id: end-of-file-fixer - - id: trailing-whitespace -- repo: https://github.com/pycqa/pylint + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + - repo: https://github.com/pycqa/pylint rev: v2.11.1 hooks: - - id: pylint + - id: pylint name: pylint (library code) types: [python] args: - --disable=consider-using-f-string exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint + - id: pylint name: pylint (example code) description: Run pylint rules on "examples/*.py" files types: [python] files: "^examples/" args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint + - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code + - id: pylint name: pylint (test code) description: Run pylint rules on "tests/*.py" files types: [python] files: "^tests/" args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - --disable=missing-docstring,consider-using-f-string,duplicate-code From 3fdcd15a0c08e1e59f3bad367d2de2557690c701 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:55 -0400 Subject: [PATCH 122/153] Increase min lines similarity Signed-off-by: Alec Delaney --- .pylintrc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index f0c8611..65e9c39 100644 --- a/.pylintrc +++ b/.pylintrc @@ -251,7 +251,7 @@ ignore-docstrings=yes ignore-imports=yes # Minimum lines number of a similarity. -min-similarity-lines=4 +min-similarity-lines=12 [BASIC] From 4f936f2a320ddb54103747d0b241a669fce2c485 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Sun, 22 May 2022 00:18:23 -0400 Subject: [PATCH 123/153] Switch to inclusive terminology Signed-off-by: Alec Delaney --- .pylintrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.pylintrc b/.pylintrc index 65e9c39..12a1de9 100644 --- a/.pylintrc +++ b/.pylintrc @@ -9,11 +9,11 @@ # run arbitrary code extension-pkg-whitelist= -# Add files or directories to the blacklist. They should be base names, not +# Add files or directories to the ignore-list. They should be base names, not # paths. ignore=CVS -# Add files or directories matching the regex patterns to the blacklist. The +# Add files or directories matching the regex patterns to the ignore-list. The # regex matches against base names, not paths. ignore-patterns= From 7de4fe65ddadcb6191685536fe661153cac447a7 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 30 May 2022 14:25:04 -0400 Subject: [PATCH 124/153] Set language to "en" for documentation Signed-off-by: Alec Delaney --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 1463aeb..9a50212 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -62,7 +62,7 @@ # # This is also used if you do content translation via gettext catalogs. # Usually you set "language" from the command line for these cases. -language = None +language = "en" # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. From 4b14b9d8406cf5bec09b3aa423b49634ffbdc509 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 7 Jun 2022 15:34:14 -0400 Subject: [PATCH 125/153] Added cp.org link to index.rst --- docs/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/index.rst b/docs/index.rst index d33ad8e..d1f7459 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -35,7 +35,8 @@ Table of Contents .. toctree:: :caption: Other Links - Download + Download from GitHub + Download Library Bundle CircuitPython Reference Documentation CircuitPython Support Forum Discord Chat From 901f907f353c54c8a07dd5056c4284e1cff8273c Mon Sep 17 00:00:00 2001 From: evaherrada Date: Fri, 22 Jul 2022 13:58:40 -0400 Subject: [PATCH 126/153] Changed .env to .venv in README.rst --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 2d7ed92..bafc3c3 100644 --- a/README.rst +++ b/README.rst @@ -57,8 +57,8 @@ To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .env - source .env/bin/activate + python3 -m venv .venv + source .venv/bin/activate pip3 install adafruit-circuitpython-dht Usage Example From 47cbc513885f9a9c47dfa6f7147a3625028135f9 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Tue, 2 Aug 2022 17:00:29 -0400 Subject: [PATCH 127/153] Added Black formatting badge --- README.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.rst b/README.rst index bafc3c3..94f0cbc 100644 --- a/README.rst +++ b/README.rst @@ -15,6 +15,10 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_DHT/actions :alt: Build Status +.. image:: https://img.shields.io/badge/code%20style-black-000000.svg + :target: https://github.com/psf/black + :alt: Code Style: Black + CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. Dependencies From 7707c5dd341eee4f42df4074fdbff84ec9b4f2dd Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 8 Aug 2022 22:05:52 -0400 Subject: [PATCH 128/153] Switched to pyproject.toml --- .github/workflows/build.yml | 18 ++++++------ .github/workflows/release.yml | 17 ++++++----- optional_requirements.txt | 3 ++ pyproject.toml | 46 +++++++++++++++++++++++++++++ requirements.txt | 2 +- setup.py | 54 ----------------------------------- 6 files changed, 70 insertions(+), 70 deletions(-) create mode 100644 optional_requirements.txt create mode 100644 pyproject.toml delete mode 100644 setup.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 474520d..22f6582 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -47,6 +47,8 @@ jobs: pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - name: Library version run: git describe --dirty --always --tags + - name: Setup problem matchers + uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - name: Pre-commit hooks run: | pre-commit run --all-files @@ -60,16 +62,16 @@ jobs: - name: Build docs working-directory: docs run: sphinx-build -E -W -b html . _build/html - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Build Python package - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | - pip install --upgrade setuptools wheel twine readme_renderer testresources - python setup.py sdist - python setup.py bdist_wheel --universal + pip install --upgrade build twine + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + done; + python -m build twine check dist/* - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a65e5de..d1b4f8d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,25 +61,28 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v1 - - name: Check For setup.py + - name: Check For pyproject.toml id: need-pypi run: | - echo ::set-output name=setup-py::$( find . -wholename './setup.py' ) + echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - name: Set up Python - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') uses: actions/setup-python@v2 with: python-version: '3.x' - name: Install dependencies - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') run: | python -m pip install --upgrade pip - pip install setuptools wheel twine + pip install --upgrade build twine - name: Build and publish - if: contains(steps.need-pypi.outputs.setup-py, 'setup.py') + if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') env: TWINE_USERNAME: ${{ secrets.pypi_username }} TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | - python setup.py sdist + for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do + sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + done; + python -m build twine upload dist/* diff --git a/optional_requirements.txt b/optional_requirements.txt new file mode 100644 index 0000000..d4e27c4 --- /dev/null +++ b/optional_requirements.txt @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..0f6e4d2 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,46 @@ +# SPDX-FileCopyrightText: 2022 Alec Delaney for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +[build-system] +requires = [ + "setuptools", + "wheel", +] + +[project] +name = "adafruit-circuitpython-dht" +description = "CircuitPython support for DHT11 and DHT22 type temperature/humidity devices" +version = "0.0.0-auto.0" +readme = "README.rst" +authors = [ + {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} +] +urls = {Homepage = "https://github.com/adafruit/Adafruit_CircuitPython_DHT"} +keywords = [ + "adafruit", + "dht", + "hardware", + "sensors", + "temperature", + "humidity", + "micropython", + "circuitpython", +] +license = {text = "MIT"} +classifiers = [ + "Intended Audience :: Developers", + "Topic :: Software Development :: Libraries", + "Topic :: Software Development :: Embedded Systems", + "Topic :: System :: Hardware", + "License :: OSI Approved :: MIT License", + "Programming Language :: Python :: 3", +] +dynamic = ["dependencies", "optional-dependencies"] + +[tool.setuptools] +py-modules = ["adafruit_dht"] + +[tool.setuptools.dynamic] +dependencies = {file = ["requirements.txt"]} +optional-dependencies = {optional = {file = ["optional_requirements.txt"]}} diff --git a/requirements.txt b/requirements.txt index 17a850d..7a984a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2022 Alec Delaney, for Adafruit Industries # # SPDX-License-Identifier: Unlicense diff --git a/setup.py b/setup.py deleted file mode 100644 index 1689b64..0000000 --- a/setup.py +++ /dev/null @@ -1,54 +0,0 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -"""A setuptools based setup module. - -See: -https://packaging.python.org/en/latest/distributing.html -https://github.com/pypa/sampleproject -""" - -# Always prefer setuptools over distutils -from setuptools import setup, find_packages - -# To use a consistent encoding -from codecs import open -from os import path - -here = path.abspath(path.dirname(__file__)) - -# Get the long description from the README file -with open(path.join(here, "README.rst"), encoding="utf-8") as f: - long_description = f.read() - -setup( - name="adafruit-circuitpython-dht", - use_scm_version=True, - setup_requires=["setuptools_scm"], - description="CircuitPython support for DHT11 and DHT22 type temperature/humidity devices", - long_description=long_description, - long_description_content_type="text/x-rst", - # The project's main homepage. - url="https://github.com/adafruit/Adafruit_CircuitPython_DHT", - # Author details - author="Adafruit Industries", - author_email="circuitpython@adafruit.com", - install_requires=["Adafruit-Blinka"], - # Choose your license - license="MIT", - # See https://pypi.python.org/pypi?%3Aaction=list_classifiers - classifiers=[ - "Development Status :: 3 - Alpha", - "Intended Audience :: Developers", - "Topic :: Software Development :: Libraries", - "Topic :: System :: Hardware", - "License :: OSI Approved :: MIT License", - "Programming Language :: Python :: 3", - ], - # What does your project relate to? - keywords="adafruit dht hardware sensors temperature humidity micropython circuitpython", - # You can just specify the packages manually here if your project is - # simple. Or you can use find_packages(). - py_modules=["adafruit_dht"], -) From aeaf83cc729136b1d41e1e815a7819f36cbeef99 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 9 Aug 2022 12:03:54 -0400 Subject: [PATCH 129/153] Add setuptools-scm to build system requirements Signed-off-by: Alec Delaney --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 0f6e4d2..82d71e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,6 +6,7 @@ requires = [ "setuptools", "wheel", + "setuptools-scm", ] [project] From 5cfeb45ed06d782a6ab92e3007e3165fd28972e7 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 18:09:13 -0400 Subject: [PATCH 130/153] Update version string --- adafruit_dht.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 6653c83..f173cd8 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -46,7 +46,7 @@ except ImportError: pass -__version__ = "0.0.0-auto.0" +__version__ = "0.0.0+auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_DHT.git" diff --git a/pyproject.toml b/pyproject.toml index 82d71e4..0707c3d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -12,7 +12,7 @@ requires = [ [project] name = "adafruit-circuitpython-dht" description = "CircuitPython support for DHT11 and DHT22 type temperature/humidity devices" -version = "0.0.0-auto.0" +version = "0.0.0+auto.0" readme = "README.rst" authors = [ {name = "Adafruit Industries", email = "circuitpython@adafruit.com"} From 1323cd9f30b6217ecdefcba99b28f8c2055b4229 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 16 Aug 2022 21:09:13 -0400 Subject: [PATCH 131/153] Fix version strings in workflow files --- .github/workflows/build.yml | 2 +- .github/workflows/release.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 22f6582..cb2f60e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -71,7 +71,7 @@ jobs: run: | pip install --upgrade build twine for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/1.2.3/" $file; + sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; done; python -m build twine check dist/* diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1b4f8d..f3a0325 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -82,7 +82,7 @@ jobs: TWINE_PASSWORD: ${{ secrets.pypi_password }} run: | for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0-auto.0/${{github.event.release.tag_name}}/" $file; + sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; done; python -m build twine upload dist/* From 42bf709160e91ffe3424719fef7c450d5010e5b7 Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Mon, 22 Aug 2022 21:36:30 -0400 Subject: [PATCH 132/153] Keep copyright up to date in documentation --- docs/conf.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index 9a50212..cf5bb54 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -6,6 +6,7 @@ import os import sys +import datetime sys.path.insert(0, os.path.abspath("..")) @@ -45,7 +46,8 @@ # General information about the project. project = "Adafruit CircuitPython DHT Library" -copyright = "2017 Mike McWethy" +current_year = str(datetime.datetime.now().year) +copyright = current_year + " Mike McWethy" author = "Mike McWethy" # The version info for the project you're documenting, acts as replacement for From 63cb0190a9818a26e5ebffc55776f0f67525a66b Mon Sep 17 00:00:00 2001 From: Alec Delaney Date: Tue, 23 Aug 2022 17:26:20 -0400 Subject: [PATCH 133/153] Use year duration range for copyright attribution --- docs/conf.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index cf5bb54..f12324d 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -46,8 +46,14 @@ # General information about the project. project = "Adafruit CircuitPython DHT Library" +creation_year = "2017" current_year = str(datetime.datetime.now().year) -copyright = current_year + " Mike McWethy" +year_duration = ( + current_year + if current_year == creation_year + else creation_year + " - " + current_year +) +copyright = year_duration + " Mike McWethy" author = "Mike McWethy" # The version info for the project you're documenting, acts as replacement for From b273cfe8f64be62ce819ab01abebd55204b6459f Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:02:49 -0400 Subject: [PATCH 134/153] Switching to composite actions --- .github/workflows/build.yml | 67 +---------------------- .github/workflows/release.yml | 88 ------------------------------ .github/workflows/release_gh.yml | 14 +++++ .github/workflows/release_pypi.yml | 14 +++++ 4 files changed, 30 insertions(+), 153 deletions(-) delete mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/release_gh.yml create mode 100644 .github/workflows/release_pypi.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index cb2f60e..041a337 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,68 +10,5 @@ jobs: test: runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install dependencies - # (e.g. - apt-get: gettext, etc; pip: circuitpython-build-tools, requirements.txt; etc.) - run: | - source actions-ci/install.sh - - name: Pip install Sphinx, pre-commit - run: | - pip install --force-reinstall Sphinx sphinx-rtd-theme pre-commit - - name: Library version - run: git describe --dirty --always --tags - - name: Setup problem matchers - uses: adafruit/circuitpython-action-library-ci-problem-matchers@v1 - - name: Pre-commit hooks - run: | - pre-commit run --all-files - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Archive bundles - uses: actions/upload-artifact@v2 - with: - name: bundles - path: ${{ github.workspace }}/bundles/ - - name: Build docs - working-directory: docs - run: sphinx-build -E -W -b html . _build/html - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Build Python package - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - pip install --upgrade build twine - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/1.2.3/" $file; - done; - python -m build - twine check dist/* + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index f3a0325..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,88 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: MIT - -name: Release Actions - -on: - release: - types: [published] - -jobs: - upload-release-assets: - runs-on: ubuntu-latest - steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: echo "$GITHUB_CONTEXT" - - name: Translate Repo Name For Build Tools filename_prefix - id: repo-name - run: | - echo ::set-output name=repo-name::$( - echo ${{ github.repository }} | - awk -F '\/' '{ print tolower($2) }' | - tr '_' '-' - ) - - name: Set up Python 3.x - uses: actions/setup-python@v2 - with: - python-version: "3.x" - - name: Versions - run: | - python3 --version - - name: Checkout Current Repo - uses: actions/checkout@v1 - with: - submodules: true - - name: Checkout tools repo - uses: actions/checkout@v2 - with: - repository: adafruit/actions-ci-circuitpython-libs - path: actions-ci - - name: Install deps - run: | - source actions-ci/install.sh - - name: Build assets - run: circuitpython-build-bundles --filename_prefix ${{ steps.repo-name.outputs.repo-name }} --library_location . - - name: Upload Release Assets - # the 'official' actions version does not yet support dynamically - # supplying asset names to upload. @csexton's version chosen based on - # discussion in the issue below, as its the simplest to implement and - # allows for selecting files with a pattern. - # https://github.com/actions/upload-release-asset/issues/4 - #uses: actions/upload-release-asset@v1.0.1 - uses: csexton/release-asset-action@master - with: - pattern: "bundles/*" - github-token: ${{ secrets.GITHUB_TOKEN }} - - upload-pypi: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v1 - - name: Check For pyproject.toml - id: need-pypi - run: | - echo ::set-output name=pyproject-toml::$( find . -wholename './pyproject.toml' ) - - name: Set up Python - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - uses: actions/setup-python@v2 - with: - python-version: '3.x' - - name: Install dependencies - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - run: | - python -m pip install --upgrade pip - pip install --upgrade build twine - - name: Build and publish - if: contains(steps.need-pypi.outputs.pyproject-toml, 'pyproject.toml') - env: - TWINE_USERNAME: ${{ secrets.pypi_username }} - TWINE_PASSWORD: ${{ secrets.pypi_password }} - run: | - for file in $(find -not -path "./.*" -not -path "./docs*" \( -name "*.py" -o -name "*.toml" \) ); do - sed -i -e "s/0.0.0+auto.0/${{github.event.release.tag_name}}/" $file; - done; - python -m build - twine upload dist/* diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_gh.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml new file mode 100644 index 0000000..041a337 --- /dev/null +++ b/.github/workflows/release_pypi.yml @@ -0,0 +1,14 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +name: Build CI + +on: [pull_request, push] + +jobs: + test: + runs-on: ubuntu-latest + steps: + - name: Run Build CI workflow + uses: adafruit/workflows-circuitpython-libs/build@main From 5be954b9afb70e5f8350cdeffababa525735938b Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 00:46:59 -0400 Subject: [PATCH 135/153] Updated pylint version to 2.13.0 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3343606..4c43710 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.11.1 + rev: v2.13.0 hooks: - id: pylint name: pylint (library code) From ae571e3e42dda731f72fe87e7e70df9d6d01e2ea Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 08:15:19 -0400 Subject: [PATCH 136/153] Update pylint to 2.15.5 --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4c43710..0e5fccc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -18,7 +18,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.13.0 + rev: v2.15.5 hooks: - id: pylint name: pylint (library code) From bab78e6033187248017d69dde4f46a79ab77cde1 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 09:12:43 -0400 Subject: [PATCH 137/153] Fix release CI files --- .github/workflows/release_gh.yml | 14 +++++++++----- .github/workflows/release_pypi.yml | 15 ++++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index 041a337..b8aa8d6 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -2,13 +2,17 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: GitHub Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run GitHub Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-gh@main + with: + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/release_pypi.yml b/.github/workflows/release_pypi.yml index 041a337..65775b7 100644 --- a/.github/workflows/release_pypi.yml +++ b/.github/workflows/release_pypi.yml @@ -2,13 +2,18 @@ # # SPDX-License-Identifier: MIT -name: Build CI +name: PyPI Release Actions -on: [pull_request, push] +on: + release: + types: [published] jobs: - test: + upload-release-assets: runs-on: ubuntu-latest steps: - - name: Run Build CI workflow - uses: adafruit/workflows-circuitpython-libs/build@main + - name: Run PyPI Release CI workflow + uses: adafruit/workflows-circuitpython-libs/release-pypi@main + with: + pypi-username: ${{ secrets.pypi_username }} + pypi-password: ${{ secrets.pypi_password }} From db4977977c6653f2e01b9cee99a0b25b681670c5 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Fri, 4 Nov 2022 18:34:32 -0400 Subject: [PATCH 138/153] Update .pylintrc for v2.15.5 --- .pylintrc | 52 ++++++++-------------------------------------------- 1 file changed, 8 insertions(+), 44 deletions(-) diff --git a/.pylintrc b/.pylintrc index 12a1de9..40208c3 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # # SPDX-License-Identifier: Unlicense @@ -26,7 +26,7 @@ jobs=1 # List of plugins (as comma separated values of python modules names) to load, # usually to register additional checkers. -load-plugins= +load-plugins=pylint.extensions.no_self_use # Pickle collected data for later comparisons. persistent=yes @@ -54,8 +54,8 @@ confidence= # --enable=similarities". If you want to run only the classes checker, but have # no Warning level messages displayed, use"--disable=all --enable=classes # --disable=W" -# disable=import-error,print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call -disable=print-statement,parameter-unpacking,unpacking-in-except,old-raise-syntax,backtick,long-suffix,old-ne-operator,old-octal-literal,import-star-module-level,raw-checker-failed,bad-inline-option,locally-disabled,locally-enabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,apply-builtin,basestring-builtin,buffer-builtin,cmp-builtin,coerce-builtin,execfile-builtin,file-builtin,long-builtin,raw_input-builtin,reduce-builtin,standarderror-builtin,unicode-builtin,xrange-builtin,coerce-method,delslice-method,getslice-method,setslice-method,no-absolute-import,old-division,dict-iter-method,dict-view-method,next-method-called,metaclass-assignment,indexing-exception,raising-string,reload-builtin,oct-method,hex-method,nonzero-method,cmp-method,input-builtin,round-builtin,intern-builtin,unichr-builtin,map-builtin-not-iterating,zip-builtin-not-iterating,range-builtin-not-iterating,filter-builtin-not-iterating,using-cmp-argument,eq-without-hash,div-method,idiv-method,rdiv-method,exception-message-attribute,invalid-str-codec,sys-max-int,bad-python3-import,deprecated-string-function,deprecated-str-translate-call,import-error,bad-continuation,unspecified-encoding +# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call +disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding # Enable the message, report, category or checker with the given id(s). You can # either give multiple identifier separated by comma (,) or put this option @@ -122,7 +122,8 @@ spelling-store-unknown-words=no [MISCELLANEOUS] # List of note tags to take in consideration, separated by a comma. -notes=FIXME,XXX,TODO +# notes=FIXME,XXX,TODO +notes=FIXME,XXX [TYPECHECK] @@ -224,12 +225,6 @@ max-line-length=100 # Maximum number of lines in a module max-module-lines=1000 -# List of optional constructs for which whitespace checking is disabled. `dict- -# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}. -# `trailing-comma` allows a space between comma and closing bracket: (a, ). -# `empty-line` allows space-only lines. -no-space-check=trailing-comma,dict-separator - # Allow the body of a class to be on the same line as the declaration if body # contains single statement. single-line-class-stmt=no @@ -256,38 +251,22 @@ min-similarity-lines=12 [BASIC] -# Naming hint for argument names -argument-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct argument names argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for attribute names -attr-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct attribute names attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Bad variable names which should always be refused, separated by a comma bad-names=foo,bar,baz,toto,tutu,tata -# Naming hint for class attribute names -class-attribute-name-hint=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - # Regular expression matching correct class attribute names class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ -# Naming hint for class names -# class-name-hint=[A-Z_][a-zA-Z0-9]+$ -class-name-hint=[A-Z_][a-zA-Z0-9_]+$ - # Regular expression matching correct class names # class-rgx=[A-Z_][a-zA-Z0-9]+$ class-rgx=[A-Z_][a-zA-Z0-9_]+$ -# Naming hint for constant names -const-name-hint=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - # Regular expression matching correct constant names const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ @@ -295,34 +274,22 @@ const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ # ones are exempt. docstring-min-length=-1 -# Naming hint for function names -function-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct function names function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ # Good variable names which should always be accepted, separated by a comma # good-names=i,j,k,ex,Run,_ -good-names=r,g,b,i,j,k,n,ex,Run,_ +good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ # Include a hint for the correct naming format with invalid-name include-naming-hint=no -# Naming hint for inline iteration names -inlinevar-name-hint=[A-Za-z_][A-Za-z0-9_]*$ - # Regular expression matching correct inline iteration names inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ -# Naming hint for method names -method-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct method names method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ -# Naming hint for module names -module-name-hint=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - # Regular expression matching correct module names module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ @@ -338,9 +305,6 @@ no-docstring-rgx=^_ # to this list to register other decorators that produce valid properties. property-classes=abc.abstractproperty -# Naming hint for variable names -variable-name-hint=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - # Regular expression matching correct variable names variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ @@ -425,7 +389,7 @@ max-returns=6 max-statements=50 # Minimum number of public methods for a class (see R0903). -min-public-methods=2 +min-public-methods=1 [EXCEPTIONS] From c7f401b068a7b3e9f4678b82be916de9fbd5f8e5 Mon Sep 17 00:00:00 2001 From: evaherrada Date: Thu, 10 Nov 2022 14:28:53 -0500 Subject: [PATCH 139/153] Fixed linting --- examples/dht_time_calibration_advance.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index d60b7ac..8b0731e 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -87,10 +87,8 @@ # Gather the highest read numbers from all reads done. best_result = max( - [ - reads[milliseconds]["total_reads"] - for milliseconds in reads # pylint: disable=consider-using-dict-items - ] + reads[milliseconds]["total_reads"] + for milliseconds in reads # pylint: disable=consider-using-dict-items ) # Gather best time(s) in milliseconds where we got more reads best_times = [ From 2081ed29ab717111e259fbba84b4d44d9f68d5ff Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 1 Sep 2022 20:16:31 -0400 Subject: [PATCH 140/153] Add .venv to .gitignore Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 544ec4a..db3d538 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ _build # Virtual environment-specific files .env +.venv # MacOS-specific files *.DS_Store From 7badf78ecab2b5e57c658467cd7549678c6f01a9 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Thu, 19 Jan 2023 23:39:55 -0500 Subject: [PATCH 141/153] Add upload url to release action Signed-off-by: Alec Delaney <89490472+tekktrik@users.noreply.github.com> --- .github/workflows/release_gh.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/release_gh.yml b/.github/workflows/release_gh.yml index b8aa8d6..9acec60 100644 --- a/.github/workflows/release_gh.yml +++ b/.github/workflows/release_gh.yml @@ -16,3 +16,4 @@ jobs: uses: adafruit/workflows-circuitpython-libs/release-gh@main with: github-token: ${{ secrets.GITHUB_TOKEN }} + upload-url: ${{ github.event.release.upload_url }} From 2108ae19eb3bf35b6354da59142eb8b2df96f004 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Tue, 9 May 2023 20:26:25 -0400 Subject: [PATCH 142/153] Update pre-commit hooks Signed-off-by: Tekktrik --- .pre-commit-config.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0e5fccc..70ade69 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -4,21 +4,21 @@ repos: - repo: https://github.com/python/black - rev: 22.3.0 + rev: 23.3.0 hooks: - id: black - repo: https://github.com/fsfe/reuse-tool - rev: v0.14.0 + rev: v1.1.2 hooks: - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.2.0 + rev: v4.4.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/pycqa/pylint - rev: v2.15.5 + rev: v2.17.4 hooks: - id: pylint name: pylint (library code) From 7522ce1047bd267425b9223f3f3aaa80d005a257 Mon Sep 17 00:00:00 2001 From: Tekktrik Date: Thu, 11 May 2023 00:58:04 -0400 Subject: [PATCH 143/153] Linted per pre-commit --- adafruit_dht.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index f173cd8..2d838bd 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -79,7 +79,7 @@ def __init__( self._temperature = None self._use_pulseio = use_pulseio if "Linux" not in uname() and not self._use_pulseio: - raise Exception("Bitbanging is not supported when using CircuitPython.") + raise ValueError("Bitbanging is not supported when using CircuitPython.") # We don't use a context because linux-based systems are sluggish # and we're better off having a running process if self._use_pulseio: From b092f90e7a741e9dec0821aaca93c6d7fa05e414 Mon Sep 17 00:00:00 2001 From: xgqfrms Date: Tue, 16 May 2023 23:24:55 +0800 Subject: [PATCH 144/153] fix: the issues 90 https://github.com/adafruit/Adafruit_CircuitPython_DHT/issues/90 --- adafruit_dht.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index 2d838bd..d4d869a 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -89,7 +89,6 @@ def __init__( def exit(self) -> None: """Cleans up the PulseIn process. Must be called explicitly""" if self._use_pulseio: - print("De-initializing self.pulse_in") self.pulse_in.deinit() def _pulses_to_binary(self, pulses: array.array, start: int, stop: int) -> int: From e32bad46a3bfafe9ecc1ba4f59f21c049a098758 Mon Sep 17 00:00:00 2001 From: Alec Delaney <89490472+tekktrik@users.noreply.github.com> Date: Tue, 23 May 2023 22:59:18 -0400 Subject: [PATCH 145/153] Update .pylintrc, fix jQuery for docs --- .pylintrc | 2 +- docs/conf.py | 1 + docs/requirements.txt | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.pylintrc b/.pylintrc index 40208c3..f945e92 100644 --- a/.pylintrc +++ b/.pylintrc @@ -396,4 +396,4 @@ min-public-methods=1 # Exceptions that will emit a warning when being caught. Defaults to # "Exception" -overgeneral-exceptions=Exception +overgeneral-exceptions=builtins.Exception diff --git a/docs/conf.py b/docs/conf.py index f12324d..4ecebe1 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -17,6 +17,7 @@ # ones. extensions = [ "sphinx.ext.autodoc", + "sphinxcontrib.jquery", "sphinx.ext.intersphinx", "sphinx.ext.viewcode", ] diff --git a/docs/requirements.txt b/docs/requirements.txt index 88e6733..797aa04 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -3,3 +3,4 @@ # SPDX-License-Identifier: Unlicense sphinx>=4.0.0 +sphinxcontrib-jquery From 7e91a4bb226367d050c7a4751a5982645c770a27 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 18 Sep 2023 17:20:11 -0500 Subject: [PATCH 146/153] fix rtd theme --- docs/conf.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/docs/conf.py b/docs/conf.py index 4ecebe1..d974d8c 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -102,19 +102,10 @@ # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -on_rtd = os.environ.get("READTHEDOCS", None) == "True" - -if not on_rtd: # only import and set the theme if we're building docs locally - try: - import sphinx_rtd_theme - - html_theme = "sphinx_rtd_theme" - html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] - except: - html_theme = "default" - html_theme_path = ["."] -else: - html_theme_path = ["."] +import sphinx_rtd_theme + +html_theme = "sphinx_rtd_theme" +html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From b7e9b55c3ecc015cc65a2968f685ebf4e354f752 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 4 Dec 2023 11:21:52 -0600 Subject: [PATCH 147/153] unpin sphinx and add sphinx-rtd-theme to docs reqs --- docs/requirements.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/requirements.txt b/docs/requirements.txt index 797aa04..979f568 100644 --- a/docs/requirements.txt +++ b/docs/requirements.txt @@ -2,5 +2,6 @@ # # SPDX-License-Identifier: Unlicense -sphinx>=4.0.0 +sphinx sphinxcontrib-jquery +sphinx-rtd-theme From a6e6c6316b9349d7a9debf7bca7bb5783226e6c9 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Mon, 7 Oct 2024 09:24:05 -0500 Subject: [PATCH 148/153] remove deprecated get_html_theme_path() call Signed-off-by: foamyguy --- docs/conf.py | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index d974d8c..15ccd33 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -105,7 +105,6 @@ import sphinx_rtd_theme html_theme = "sphinx_rtd_theme" -html_theme_path = [sphinx_rtd_theme.get_html_theme_path(), "."] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, From e561725f97c9d2f3b4956e2b6d8c1d57741932f2 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 13 Nov 2024 15:16:21 -0600 Subject: [PATCH 149/153] read decimal value also --- adafruit_dht.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/adafruit_dht.py b/adafruit_dht.py index d4d869a..5c6f882 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -235,8 +235,8 @@ def measure(self) -> None: if self._dht11: # humidity is 1 byte new_humidity = buf[0] - # temperature is 1 byte - new_temperature = buf[2] + # temperature is 1 byte for integral and 1 byte for 1st decimal place + new_temperature = buf[2] + (buf[3] & 0x0F) / 10 else: # humidity is 2 bytes new_humidity = ((buf[0] << 8) | buf[1]) / 10 From eb53bb1f10b094044e64dbea1f1417e5b533fba4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 14 Jan 2025 11:32:34 -0600 Subject: [PATCH 150/153] add sphinx configuration to rtd.yaml Signed-off-by: foamyguy --- .readthedocs.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 33c2a61..88bca9f 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -8,6 +8,9 @@ # Required version: 2 +sphinx: + configuration: docs/conf.py + build: os: ubuntu-20.04 tools: From 232821f44c8dc0a795d03d636d44cbc41f1ae2ba Mon Sep 17 00:00:00 2001 From: foamyguy Date: Tue, 13 May 2025 21:59:19 +0000 Subject: [PATCH 151/153] change to ruff --- .gitattributes | 11 + .pre-commit-config.yaml | 43 +-- .pylintrc | 399 ----------------------- README.rst | 6 +- adafruit_dht.py | 12 +- docs/api.rst | 6 + docs/conf.py | 8 +- examples/dht_simpletest.py | 8 +- examples/dht_time_calibration_advance.py | 13 +- examples/dht_to_led_display.py | 8 +- ruff.toml | 105 ++++++ 11 files changed, 153 insertions(+), 466 deletions(-) create mode 100644 .gitattributes delete mode 100644 .pylintrc create mode 100644 ruff.toml diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..21c125c --- /dev/null +++ b/.gitattributes @@ -0,0 +1,11 @@ +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries +# +# SPDX-License-Identifier: Unlicense + +.py text eol=lf +.rst text eol=lf +.txt text eol=lf +.yaml text eol=lf +.toml text eol=lf +.license text eol=lf +.md text eol=lf diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70ade69..ff19dde 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,42 +1,21 @@ -# SPDX-FileCopyrightText: 2020 Diego Elio Pettenò +# SPDX-FileCopyrightText: 2024 Justin Myers for Adafruit Industries # # SPDX-License-Identifier: Unlicense repos: - - repo: https://github.com/python/black - rev: 23.3.0 - hooks: - - id: black - - repo: https://github.com/fsfe/reuse-tool - rev: v1.1.2 - hooks: - - id: reuse - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-yaml - id: end-of-file-fixer - id: trailing-whitespace - - repo: https://github.com/pycqa/pylint - rev: v2.17.4 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.3.4 hooks: - - id: pylint - name: pylint (library code) - types: [python] - args: - - --disable=consider-using-f-string - exclude: "^(docs/|examples/|tests/|setup.py$)" - - id: pylint - name: pylint (example code) - description: Run pylint rules on "examples/*.py" files - types: [python] - files: "^examples/" - args: - - --disable=missing-docstring,invalid-name,consider-using-f-string,duplicate-code - - id: pylint - name: pylint (test code) - description: Run pylint rules on "tests/*.py" files - types: [python] - files: "^tests/" - args: - - --disable=missing-docstring,consider-using-f-string,duplicate-code + - id: ruff-format + - id: ruff + args: ["--fix"] + - repo: https://github.com/fsfe/reuse-tool + rev: v3.0.1 + hooks: + - id: reuse diff --git a/.pylintrc b/.pylintrc deleted file mode 100644 index f945e92..0000000 --- a/.pylintrc +++ /dev/null @@ -1,399 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# -# SPDX-License-Identifier: Unlicense - -[MASTER] - -# A comma-separated list of package or module names from where C extensions may -# be loaded. Extensions are loading into the active Python interpreter and may -# run arbitrary code -extension-pkg-whitelist= - -# Add files or directories to the ignore-list. They should be base names, not -# paths. -ignore=CVS - -# Add files or directories matching the regex patterns to the ignore-list. The -# regex matches against base names, not paths. -ignore-patterns= - -# Python code to execute, usually for sys.path manipulation such as -# pygtk.require(). -#init-hook= - -# Use multiple processes to speed up Pylint. -jobs=1 - -# List of plugins (as comma separated values of python modules names) to load, -# usually to register additional checkers. -load-plugins=pylint.extensions.no_self_use - -# Pickle collected data for later comparisons. -persistent=yes - -# Specify a configuration file. -#rcfile= - -# Allow loading of arbitrary C extensions. Extensions are imported into the -# active Python interpreter and may run arbitrary code. -unsafe-load-any-extension=no - - -[MESSAGES CONTROL] - -# Only show warnings with the listed confidence levels. Leave empty to show -# all. Valid levels: HIGH, INFERENCE, INFERENCE_FAILURE, UNDEFINED -confidence= - -# Disable the message, report, category or checker with the given id(s). You -# can either give multiple identifiers separated by comma (,) or put this -# option multiple times (only on the command line, not in the configuration -# file where it should appear only once).You can also use "--disable=all" to -# disable everything first and then reenable specific checks. For example, if -# you want to run only the similarities checker, you can use "--disable=all -# --enable=similarities". If you want to run only the classes checker, but have -# no Warning level messages displayed, use"--disable=all --enable=classes -# --disable=W" -# disable=import-error,raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,deprecated-str-translate-call -disable=raw-checker-failed,bad-inline-option,locally-disabled,file-ignored,suppressed-message,useless-suppression,deprecated-pragma,import-error,pointless-string-statement,unspecified-encoding - -# Enable the message, report, category or checker with the given id(s). You can -# either give multiple identifier separated by comma (,) or put this option -# multiple time (only on the command line, not in the configuration file where -# it should appear only once). See also the "--disable" option for examples. -enable= - - -[REPORTS] - -# Python expression which should return a note less than 10 (10 is the highest -# note). You have access to the variables errors warning, statement which -# respectively contain the number of errors / warnings messages and the total -# number of statements analyzed. This is used by the global evaluation report -# (RP0004). -evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10) - -# Template used to display messages. This is a python new-style format string -# used to format the message information. See doc for all details -#msg-template= - -# Set the output format. Available formats are text, parseable, colorized, json -# and msvs (visual studio).You can also give a reporter class, eg -# mypackage.mymodule.MyReporterClass. -output-format=text - -# Tells whether to display a full report or only the messages -reports=no - -# Activate the evaluation score. -score=yes - - -[REFACTORING] - -# Maximum number of nested blocks for function / method body -max-nested-blocks=5 - - -[LOGGING] - -# Logging modules to check that the string format arguments are in logging -# function parameter format -logging-modules=logging - - -[SPELLING] - -# Spelling dictionary name. Available dictionaries: none. To make it working -# install python-enchant package. -spelling-dict= - -# List of comma separated words that should not be checked. -spelling-ignore-words= - -# A path to a file that contains private dictionary; one word per line. -spelling-private-dict-file= - -# Tells whether to store unknown words to indicated private dictionary in -# --spelling-private-dict-file option instead of raising a message. -spelling-store-unknown-words=no - - -[MISCELLANEOUS] - -# List of note tags to take in consideration, separated by a comma. -# notes=FIXME,XXX,TODO -notes=FIXME,XXX - - -[TYPECHECK] - -# List of decorators that produce context managers, such as -# contextlib.contextmanager. Add to this list to register other decorators that -# produce valid context managers. -contextmanager-decorators=contextlib.contextmanager - -# List of members which are set dynamically and missed by pylint inference -# system, and so shouldn't trigger E1101 when accessed. Python regular -# expressions are accepted. -generated-members= - -# Tells whether missing members accessed in mixin class should be ignored. A -# mixin class is detected if its name ends with "mixin" (case insensitive). -ignore-mixin-members=yes - -# This flag controls whether pylint should warn about no-member and similar -# checks whenever an opaque object is returned when inferring. The inference -# can return multiple potential results while evaluating a Python object, but -# some branches might not be evaluated, which results in partial inference. In -# that case, it might be useful to still emit no-member and other checks for -# the rest of the inferred objects. -ignore-on-opaque-inference=yes - -# List of class names for which member attributes should not be checked (useful -# for classes with dynamically set attributes). This supports the use of -# qualified names. -ignored-classes=optparse.Values,thread._local,_thread._local - -# List of module names for which member attributes should not be checked -# (useful for modules/projects where namespaces are manipulated during runtime -# and thus existing member attributes cannot be deduced by static analysis. It -# supports qualified module names, as well as Unix pattern matching. -ignored-modules=board - -# Show a hint with possible names when a member name was not found. The aspect -# of finding the hint is based on edit distance. -missing-member-hint=yes - -# The minimum edit distance a name should have in order to be considered a -# similar match for a missing member name. -missing-member-hint-distance=1 - -# The total number of similar names that should be taken in consideration when -# showing a hint for a missing member. -missing-member-max-choices=1 - - -[VARIABLES] - -# List of additional names supposed to be defined in builtins. Remember that -# you should avoid to define new builtins when possible. -additional-builtins= - -# Tells whether unused global variables should be treated as a violation. -allow-global-unused-variables=yes - -# List of strings which can identify a callback function by name. A callback -# name must start or end with one of those strings. -callbacks=cb_,_cb - -# A regular expression matching the name of dummy variables (i.e. expectedly -# not used). -dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_ - -# Argument names that match this expression will be ignored. Default to name -# with leading underscore -ignored-argument-names=_.*|^ignored_|^unused_ - -# Tells whether we should check for unused import in __init__ files. -init-import=no - -# List of qualified module names which can have objects that can redefine -# builtins. -redefining-builtins-modules=six.moves,future.builtins - - -[FORMAT] - -# Expected format of line ending, e.g. empty (any line ending), LF or CRLF. -# expected-line-ending-format= -expected-line-ending-format=LF - -# Regexp for a line that is allowed to be longer than the limit. -ignore-long-lines=^\s*(# )??$ - -# Number of spaces of indent required inside a hanging or continued line. -indent-after-paren=4 - -# String used as indentation unit. This is usually " " (4 spaces) or "\t" (1 -# tab). -indent-string=' ' - -# Maximum number of characters on a single line. -max-line-length=100 - -# Maximum number of lines in a module -max-module-lines=1000 - -# Allow the body of a class to be on the same line as the declaration if body -# contains single statement. -single-line-class-stmt=no - -# Allow the body of an if to be on the same line as the test if there is no -# else. -single-line-if-stmt=no - - -[SIMILARITIES] - -# Ignore comments when computing similarities. -ignore-comments=yes - -# Ignore docstrings when computing similarities. -ignore-docstrings=yes - -# Ignore imports when computing similarities. -ignore-imports=yes - -# Minimum lines number of a similarity. -min-similarity-lines=12 - - -[BASIC] - -# Regular expression matching correct argument names -argument-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct attribute names -attr-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Bad variable names which should always be refused, separated by a comma -bad-names=foo,bar,baz,toto,tutu,tata - -# Regular expression matching correct class attribute names -class-attribute-rgx=([A-Za-z_][A-Za-z0-9_]{2,30}|(__.*__))$ - -# Regular expression matching correct class names -# class-rgx=[A-Z_][a-zA-Z0-9]+$ -class-rgx=[A-Z_][a-zA-Z0-9_]+$ - -# Regular expression matching correct constant names -const-rgx=(([A-Z_][A-Z0-9_]*)|(__.*__))$ - -# Minimum line length for functions/classes that require docstrings, shorter -# ones are exempt. -docstring-min-length=-1 - -# Regular expression matching correct function names -function-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Good variable names which should always be accepted, separated by a comma -# good-names=i,j,k,ex,Run,_ -good-names=r,g,b,w,i,j,k,n,x,y,z,ex,ok,Run,_ - -# Include a hint for the correct naming format with invalid-name -include-naming-hint=no - -# Regular expression matching correct inline iteration names -inlinevar-rgx=[A-Za-z_][A-Za-z0-9_]*$ - -# Regular expression matching correct method names -method-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - -# Regular expression matching correct module names -module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$ - -# Colon-delimited sets of names that determine each other's naming style when -# the name regexes allow several styles. -name-group= - -# Regular expression which should only match function or class names that do -# not require a docstring. -no-docstring-rgx=^_ - -# List of decorators that produce properties, such as abc.abstractproperty. Add -# to this list to register other decorators that produce valid properties. -property-classes=abc.abstractproperty - -# Regular expression matching correct variable names -variable-rgx=(([a-z][a-z0-9_]{2,30})|(_[a-z0-9_]*))$ - - -[IMPORTS] - -# Allow wildcard imports from modules that define __all__. -allow-wildcard-with-all=no - -# Analyse import fallback blocks. This can be used to support both Python 2 and -# 3 compatible code, which means that the block might have code that exists -# only in one or another interpreter, leading to false positives when analysed. -analyse-fallback-blocks=no - -# Deprecated modules which should not be used, separated by a comma -deprecated-modules=optparse,tkinter.tix - -# Create a graph of external dependencies in the given file (report RP0402 must -# not be disabled) -ext-import-graph= - -# Create a graph of every (i.e. internal and external) dependencies in the -# given file (report RP0402 must not be disabled) -import-graph= - -# Create a graph of internal dependencies in the given file (report RP0402 must -# not be disabled) -int-import-graph= - -# Force import order to recognize a module as part of the standard -# compatibility libraries. -known-standard-library= - -# Force import order to recognize a module as part of a third party library. -known-third-party=enchant - - -[CLASSES] - -# List of method names used to declare (i.e. assign) instance attributes. -defining-attr-methods=__init__,__new__,setUp - -# List of member names, which should be excluded from the protected access -# warning. -exclude-protected=_asdict,_fields,_replace,_source,_make - -# List of valid names for the first argument in a class method. -valid-classmethod-first-arg=cls - -# List of valid names for the first argument in a metaclass class method. -valid-metaclass-classmethod-first-arg=mcs - - -[DESIGN] - -# Maximum number of arguments for function / method -max-args=5 - -# Maximum number of attributes for a class (see R0902). -# max-attributes=7 -max-attributes=11 - -# Maximum number of boolean expressions in a if statement -max-bool-expr=5 - -# Maximum number of branch for function / method body -max-branches=12 - -# Maximum number of locals for function / method body -max-locals=15 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=20 - -# Maximum number of return / yield for function / method body -max-returns=6 - -# Maximum number of statements in function / method body -max-statements=50 - -# Minimum number of public methods for a class (see R0903). -min-public-methods=1 - - -[EXCEPTIONS] - -# Exceptions that will emit a warning when being caught. Defaults to -# "Exception" -overgeneral-exceptions=builtins.Exception diff --git a/README.rst b/README.rst index 94f0cbc..a040868 100644 --- a/README.rst +++ b/README.rst @@ -15,9 +15,9 @@ Introduction :target: https://github.com/adafruit/Adafruit_CircuitPython_DHT/actions :alt: Build Status -.. image:: https://img.shields.io/badge/code%20style-black-000000.svg - :target: https://github.com/psf/black - :alt: Code Style: Black +.. image:: https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json + :target: https://github.com/astral-sh/ruff + :alt: Code Style: Ruff CircuitPython support for the DHT11 and DHT22 temperature and humidity devices. diff --git a/adafruit_dht.py b/adafruit_dht.py index 5c6f882..bba1da3 100644 --- a/adafruit_dht.py +++ b/adafruit_dht.py @@ -29,7 +29,8 @@ import array import time from os import uname -from digitalio import DigitalInOut, Pull, Direction + +from digitalio import DigitalInOut, Direction, Pull _USE_PULSEIO = False try: @@ -42,6 +43,7 @@ try: # Used only for typing from typing import Union + from microcontroller import Pin except ImportError: pass @@ -62,13 +64,7 @@ class DHTBase: __hiLevel = 51 def __init__( - self, - dht11: bool, - pin: Pin, - trig_wait: int, - use_pulseio: bool, - *, - max_pulses: int = 81 + self, dht11: bool, pin: Pin, trig_wait: int, use_pulseio: bool, *, max_pulses: int = 81 ): self._dht11 = dht11 self._pin = pin diff --git a/docs/api.rst b/docs/api.rst index 8cf4027..d234a8b 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -1,5 +1,11 @@ .. If you created a package, create one automodule per module in the package. +.. If your library file(s) are nested in a directory (e.g. /adafruit_foo/foo.py) +.. use this format as the module name: "adafruit_foo.foo" + +API Reference +############# + .. automodule:: adafruit_dht :members: diff --git a/docs/conf.py b/docs/conf.py index 15ccd33..9ad7edb 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -1,12 +1,10 @@ -# -*- coding: utf-8 -*- - # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # # SPDX-License-Identifier: MIT +import datetime import os import sys -import datetime sys.path.insert(0, os.path.abspath("..")) @@ -50,9 +48,7 @@ creation_year = "2017" current_year = str(datetime.datetime.now().year) year_duration = ( - current_year - if current_year == creation_year - else creation_year + " - " + current_year + current_year if current_year == creation_year else creation_year + " - " + current_year ) copyright = year_duration + " Mike McWethy" author = "Mike McWethy" diff --git a/examples/dht_simpletest.py b/examples/dht_simpletest.py index 5b3a482..bea4491 100644 --- a/examples/dht_simpletest.py +++ b/examples/dht_simpletest.py @@ -2,7 +2,9 @@ # SPDX-License-Identifier: MIT import time + import board + import adafruit_dht # Initial the dht device, with data pin connected to: @@ -19,11 +21,7 @@ temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity - print( - "Temp: {:.1f} F / {:.1f} C Humidity: {}% ".format( - temperature_f, temperature_c, humidity - ) - ) + print(f"Temp: {temperature_f:.1f} F / {temperature_c:.1f} C Humidity: {humidity}% ") except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going diff --git a/examples/dht_time_calibration_advance.py b/examples/dht_time_calibration_advance.py index 8b0731e..b67a95e 100644 --- a/examples/dht_time_calibration_advance.py +++ b/examples/dht_time_calibration_advance.py @@ -51,10 +51,8 @@ # Instantiate the DHT11 object. dhtDevice = adafruit_dht.DHT11(pin=getattr(board, pin_to_use)) # Change the default wait time for triggering the read. - # pylint: disable=protected-access dhtDevice._trig_wait = milliseconds - # pylint: disable=protected-access print(f"Using 'trig_wait' of {dhtDevice._trig_wait}") # Reset the read count for next loop reads_count = 0 @@ -75,7 +73,7 @@ reads[milliseconds][try_number] = read_values reads_count += 1 - except RuntimeError as e: + except RuntimeError: time.sleep(2) else: time.sleep(1) @@ -86,15 +84,10 @@ dhtDevice.exit() # Gather the highest read numbers from all reads done. -best_result = max( - reads[milliseconds]["total_reads"] - for milliseconds in reads # pylint: disable=consider-using-dict-items -) +best_result = max(reads[milliseconds]["total_reads"] for milliseconds in reads) # Gather best time(s) in milliseconds where we got more reads best_times = [ - milliseconds - for milliseconds in reads # pylint: disable=consider-using-dict-items - if reads[milliseconds]["total_reads"] == best_result + milliseconds for milliseconds in reads if reads[milliseconds]["total_reads"] == best_result ] print( f"Maximum reads: {best_result} out of {max_retries_per_time} with the " diff --git a/examples/dht_to_led_display.py b/examples/dht_to_led_display.py index 76434ca..e9e0d7b 100644 --- a/examples/dht_to_led_display.py +++ b/examples/dht_to_led_display.py @@ -6,14 +6,16 @@ and displaying results to the serial port and a 8 digit 7-segment display the DHT device data wire is connected to board.D2 """ + # import for dht devices and 7-segment display devices import time -from board import D2, TX, RX, D1 + import busio import digitalio from adafruit_max7219 import bcddigits -import adafruit_dht +from board import D1, D2, RX, TX +import adafruit_dht clk = RX din = TX @@ -34,7 +36,7 @@ # now show the values on the 8 digit 7-segment display display.clear_all() - display.show_str(0, "{:5.1f}{:5.1f}".format(temperature, humidity)) + display.show_str(0, f"{temperature:5.1f}{humidity:5.1f}") display.show() except RuntimeError as error: diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..36332ff --- /dev/null +++ b/ruff.toml @@ -0,0 +1,105 @@ +# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries +# +# SPDX-License-Identifier: MIT + +target-version = "py38" +line-length = 100 + +[lint] +preview = true +select = ["I", "PL", "UP"] + +extend-select = [ + "D419", # empty-docstring + "E501", # line-too-long + "W291", # trailing-whitespace + "PLC0414", # useless-import-alias + "PLC2401", # non-ascii-name + "PLC2801", # unnecessary-dunder-call + "PLC3002", # unnecessary-direct-lambda-call + "E999", # syntax-error + "PLE0101", # return-in-init + "F706", # return-outside-function + "F704", # yield-outside-function + "PLE0116", # continue-in-finally + "PLE0117", # nonlocal-without-binding + "PLE0241", # duplicate-bases + "PLE0302", # unexpected-special-method-signature + "PLE0604", # invalid-all-object + "PLE0605", # invalid-all-format + "PLE0643", # potential-index-error + "PLE0704", # misplaced-bare-raise + "PLE1141", # dict-iter-missing-items + "PLE1142", # await-outside-async + "PLE1205", # logging-too-many-args + "PLE1206", # logging-too-few-args + "PLE1307", # bad-string-format-type + "PLE1310", # bad-str-strip-call + "PLE1507", # invalid-envvar-value + "PLE2502", # bidirectional-unicode + "PLE2510", # invalid-character-backspace + "PLE2512", # invalid-character-sub + "PLE2513", # invalid-character-esc + "PLE2514", # invalid-character-nul + "PLE2515", # invalid-character-zero-width-space + "PLR0124", # comparison-with-itself + "PLR0202", # no-classmethod-decorator + "PLR0203", # no-staticmethod-decorator + "UP004", # useless-object-inheritance + "PLR0206", # property-with-parameters + "PLR0904", # too-many-public-methods + "PLR0911", # too-many-return-statements + "PLR0912", # too-many-branches + "PLR0913", # too-many-arguments + "PLR0914", # too-many-locals + "PLR0915", # too-many-statements + "PLR0916", # too-many-boolean-expressions + "PLR1702", # too-many-nested-blocks + "PLR1704", # redefined-argument-from-local + "PLR1711", # useless-return + "C416", # unnecessary-comprehension + "PLR1733", # unnecessary-dict-index-lookup + "PLR1736", # unnecessary-list-index-lookup + + # ruff reports this rule is unstable + #"PLR6301", # no-self-use + + "PLW0108", # unnecessary-lambda + "PLW0120", # useless-else-on-loop + "PLW0127", # self-assigning-variable + "PLW0129", # assert-on-string-literal + "B033", # duplicate-value + "PLW0131", # named-expr-without-context + "PLW0245", # super-without-brackets + "PLW0406", # import-self + "PLW0602", # global-variable-not-assigned + "PLW0603", # global-statement + "PLW0604", # global-at-module-level + + # fails on the try: import typing used by libraries + #"F401", # unused-import + + "F841", # unused-variable + "E722", # bare-except + "PLW0711", # binary-op-exception + "PLW1501", # bad-open-mode + "PLW1508", # invalid-envvar-default + "PLW1509", # subprocess-popen-preexec-fn + "PLW2101", # useless-with-lock + "PLW3301", # nested-min-max +] + +ignore = [ + "PLR2004", # magic-value-comparison + "UP030", # format literals + "PLW1514", # unspecified-encoding + "PLR0913", # too-many-arguments + "PLR0915", # too-many-statements + "PLR0917", # too-many-positional-arguments + "PLR0904", # too-many-public-methods + "PLR0912", # too-many-branches + "PLR0916", # too-many-boolean-expressions +] + +[format] +line-ending = "lf" From eaf62a254d4cd763f513338e0db1044fd9ac9b63 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Wed, 4 Jun 2025 10:00:20 -0500 Subject: [PATCH 152/153] update rtd.yml file Signed-off-by: foamyguy --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 88bca9f..255dafd 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -12,7 +12,7 @@ sphinx: configuration: docs/conf.py build: - os: ubuntu-20.04 + os: ubuntu-lts-latest tools: python: "3" From 3160c3b26756cd8e3608a2a6d99addefdfb58006 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Fri, 10 Oct 2025 16:18:40 -0500 Subject: [PATCH 153/153] remove deprecated ruff rule, workaround RTD theme property inline issue. Signed-off-by: foamyguy --- docs/_static/custom.css | 8 ++++++++ docs/conf.py | 3 +++ ruff.toml | 1 - 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 docs/_static/custom.css diff --git a/docs/_static/custom.css b/docs/_static/custom.css new file mode 100644 index 0000000..d60cf4b --- /dev/null +++ b/docs/_static/custom.css @@ -0,0 +1,8 @@ +/* SPDX-FileCopyrightText: 2025 Sam Blenny + * SPDX-License-Identifier: MIT + */ + +/* Monkey patch the rtd theme to prevent horizontal stacking of short items + * see https://github.com/readthedocs/sphinx_rtd_theme/issues/1301 + */ +.py.property{display: block !important;} diff --git a/docs/conf.py b/docs/conf.py index 9ad7edb..59c0c28 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -107,6 +107,9 @@ # so a file named "default.css" will overwrite the builtin "default.css". html_static_path = ["_static"] +# Include extra css to work around rtd theme glitches +html_css_files = ["custom.css"] + # The name of an image file (relative to this directory) to use as a favicon of # the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32 # pixels large. diff --git a/ruff.toml b/ruff.toml index 36332ff..9811947 100644 --- a/ruff.toml +++ b/ruff.toml @@ -17,7 +17,6 @@ extend-select = [ "PLC2401", # non-ascii-name "PLC2801", # unnecessary-dunder-call "PLC3002", # unnecessary-direct-lambda-call - "E999", # syntax-error "PLE0101", # return-in-init "F706", # return-outside-function "F704", # yield-outside-function