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_pct2075.py b/adafruit_pct2075.py index 446a6cd..f887add 100644 --- a/adafruit_pct2075.py +++ b/adafruit_pct2075.py @@ -50,36 +50,44 @@ from adafruit_register.i2c_bits import RWBits from adafruit_register.i2c_bit import RWBit import adafruit_bus_device.i2c_device as i2cdevice + __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PCT2075.git" # pylint: disable=bad-whitespace, too-few-public-methods -PCT2075_DEFAULT_ADDRESS = 0x37 # Address is configured with pins A0-A2 +PCT2075_DEFAULT_ADDRESS = 0x37 # Address is configured with pins A0-A2 + +PCT2075_REGISTER_TEMP = 0 # Temperature register (read-only) +PCT2075_REGISTER_CONFIG = 1 # Configuration register +PCT2075_REGISTER_THYST = 2 # Hysterisis register +PCT2075_REGISTER_TOS = 3 # OS register +PCT2075_REGISTER_TIDLE = 4 # Measurement idle time register -PCT2075_REGISTER_TEMP = 0 # Temperature register (read-only) -PCT2075_REGISTER_CONFIG = 1 # Configuration register -PCT2075_REGISTER_THYST = 2 # Hysterisis register -PCT2075_REGISTER_TOS = 3 # OS register -PCT2075_REGISTER_TIDLE = 4 # Measurement idle time register class Mode: """Options for `mode`""" + INTERRUPT = 1 COMPARITOR = 0 + class FaultCount: """Options for `faults_to_alert`""" + FAULT_1 = 0 FAULT_2 = 1 FAULT_4 = 2 FAULT_6 = 3 + # pylint: enable=bad-whitespace, too-few-public-methods + class PCT2075: """Driver for the PCT2075 Digital Temperature Sensor and Thermal Watchdog. :param ~busio.I2C i2c_bus: The I2C bus the INA260 is connected to. :param address: The I2C device address for the sensor. Default is ``0x37``. """ + def __init__(self, i2c_bus, address=PCT2075_DEFAULT_ADDRESS): self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address) @@ -107,7 +115,7 @@ def __init__(self, i2c_bus, address=PCT2075_DEFAULT_ADDRESS): @property def temperature(self): """Returns the current temperature in degress celsius. Resolution is 0.125 degrees C""" - return (self._temperature>>5) * 0.125 + return (self._temperature >> 5) * 0.125 @property def high_temperature_threshold(self): @@ -117,7 +125,7 @@ def high_temperature_threshold(self): @high_temperature_threshold.setter def high_temperature_threshold(self, value): - self._high_temperature_threshold = (int(value * 2) << 7) + self._high_temperature_threshold = int(value * 2) << 7 @property def temperature_hysteresis(self): @@ -125,13 +133,15 @@ def temperature_hysteresis(self): C in which the temperature is still considered high". `temperature_hysteresis` must be lower than `high_temperature_threshold`. Resolution is 0.5 degrees C. """ - return (self._temp_hysteresis >> 7) * 0.5 + return (self._temp_hysteresis >> 7) * 0.5 @temperature_hysteresis.setter def temperature_hysteresis(self, value): if value >= self.high_temperature_threshold: - raise ValueError("temperature_hysteresis must be less than high_temperature_threshold") - self._temp_hysteresis = (int(value * 2) << 7) + raise ValueError( + "temperature_hysteresis must be less than high_temperature_threshold" + ) + self._temp_hysteresis = int(value * 2) << 7 @property def faults_to_alert(self): @@ -158,6 +168,8 @@ def delay_between_measurements(self): @delay_between_measurements.setter def delay_between_measurements(self, value): if value > 3100 or value < 100 or value % 100 > 0: - raise AttributeError(""""delay_between_measurements must be >= 100 or <= 3100\ - and a multiple of 100""") - self._idle_time = int(value/100) + raise AttributeError( + """"delay_between_measurements must be >= 100 or <= 3100\ + and a multiple of 100""" + ) + self._idle_time = int(value / 100) diff --git a/docs/conf.py b/docs/conf.py index ad4187a..9918aae 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,10 +11,10 @@ # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', - 'sphinx.ext.intersphinx', - 'sphinx.ext.napoleon', - 'sphinx.ext.todo', + "sphinx.ext.autodoc", + "sphinx.ext.intersphinx", + "sphinx.ext.napoleon", + "sphinx.ext.todo", ] @@ -23,29 +24,40 @@ autodoc_mock_imports = ["adafruit_register", "adafruit_bus_device"] -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 PCT2075 Library' -copyright = u'2019 Bryan Siepert' -author = u'Bryan Siepert' +project = u"Adafruit PCT2075 Library" +copyright = u"2019 Bryan Siepert" +author = u"Bryan Siepert" # 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. @@ -57,7 +69,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. @@ -69,7 +81,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 @@ -84,59 +96,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 = 'AdafruitPct2075Librarydoc' +htmlhelp_basename = "AdafruitPct2075Librarydoc" # -- 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, 'AdafruitPCT2075Library.tex', u'AdafruitPCT2075 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitPCT2075Library.tex", + u"AdafruitPCT2075 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +159,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitPCT2075library', u'Adafruit PCT2075 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitPCT2075library", + u"Adafruit PCT2075 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +174,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitPCT2075Library', u'Adafruit PCT2075 Library Documentation', - author, 'AdafruitPCT2075Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitPCT2075Library", + u"Adafruit PCT2075 Library Documentation", + author, + "AdafruitPCT2075Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/pct2075_high_temp_alert_example.py b/examples/pct2075_high_temp_alert_example.py index 6b9a0d0..87cc66a 100644 --- a/examples/pct2075_high_temp_alert_example.py +++ b/examples/pct2075_high_temp_alert_example.py @@ -9,10 +9,10 @@ pct.high_temperature_threshold = 35.5 pct.temperature_hysteresis = 30.0 pct.high_temp_active_high = False -print("High temp alert active high? %s"%pct.high_temp_active_high) +print("High temp alert active high? %s" % pct.high_temp_active_high) # Attach an LED with the Cathode to the INT pin and Anode to 3.3V with a current limiting resistor while True: - print("Temperature: %.2f C"%pct.temperature) + print("Temperature: %.2f C" % pct.temperature) time.sleep(0.5) diff --git a/examples/pct2075_simpletest.py b/examples/pct2075_simpletest.py index 10b6f74..c040be3 100755 --- a/examples/pct2075_simpletest.py +++ b/examples/pct2075_simpletest.py @@ -2,10 +2,11 @@ import board import busio import adafruit_pct2075 + i2c = busio.I2C(board.SCL, board.SDA) pct = adafruit_pct2075.PCT2075(i2c) while True: - print("Temperature: %.2f C"%pct.temperature) + print("Temperature: %.2f C" % pct.temperature) time.sleep(0.5) diff --git a/setup.py b/setup.py index de0a120..4d79e07 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ """ from setuptools import setup, find_packages + # To use a consistent encoding from codecs import open from os import path @@ -13,53 +14,44 @@ 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-pct2075', - + name="adafruit-circuitpython-pct2075", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for the NXP PCT2075 Digital Temperature Sensor', + setup_requires=["setuptools_scm"], + description="CircuitPython library for the NXP PCT2075 Digital Temperature Sensor", 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_PCT2075', - + url="https://github.com/adafruit/Adafruit_CircuitPython_PCT2075", # Author details - author='Adafruit Industries', - author_email='circuitpython@adafruit.com', - + author="Adafruit Industries", + author_email="circuitpython@adafruit.com", install_requires=[ - 'Adafruit-Blinka', - 'adafruit-circuitpython-busdevice', - 'adafruit-circuitpython-register' + "Adafruit-Blinka", + "adafruit-circuitpython-busdevice", + "adafruit-circuitpython-register", ], - # 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 blinka circuitpython micropython pct2075 lm75 temperature', - + keywords="adafruit blinka circuitpython micropython pct2075 lm75 temperature", # You can just specify the packages manually here if your project is # simple. Or you can use find_packages(). # TODO: IF LIBRARY FILES ARE A PACKAGE FOLDER, # CHANGE `py_modules=['...']` TO `packages=['...']` - py_modules=['adafruit_pct2075'], + py_modules=["adafruit_pct2075"], )