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_mcp9600.py b/adafruit_mcp9600.py index 16a0645..80497ac 100644 --- a/adafruit_mcp9600.py +++ b/adafruit_mcp9600.py @@ -142,27 +142,27 @@ class MCP9600: _alert_2_mode = RWBit(0x9, 1) _alert_2_enable = RWBit(0x9, 0) # Alert 3 Configuration - 0xa - _alert_3_interrupt_clear = RWBit(0xa, 7) - _alert_3_monitor = RWBit(0xa, 4) - _alert_3_temp_direction = RWBit(0xa, 3) - _alert_3_state = RWBit(0xa, 2) - _alert_3_mode = RWBit(0xa, 1) - _alert_3_enable = RWBit(0xa, 0) + _alert_3_interrupt_clear = RWBit(0xA, 7) + _alert_3_monitor = RWBit(0xA, 4) + _alert_3_temp_direction = RWBit(0xA, 3) + _alert_3_state = RWBit(0xA, 2) + _alert_3_mode = RWBit(0xA, 1) + _alert_3_enable = RWBit(0xA, 0) # Alert 4 Configuration - 0xb - _alert_4_interrupt_clear = RWBit(0xb, 7) - _alert_4_monitor = RWBit(0xb, 4) - _alert_4_temp_direction = RWBit(0xb, 3) - _alert_4_state = RWBit(0xb, 2) - _alert_4_mode = RWBit(0xb, 1) - _alert_4_enable = RWBit(0xb, 0) + _alert_4_interrupt_clear = RWBit(0xB, 7) + _alert_4_monitor = RWBit(0xB, 4) + _alert_4_temp_direction = RWBit(0xB, 3) + _alert_4_state = RWBit(0xB, 2) + _alert_4_mode = RWBit(0xB, 1) + _alert_4_enable = RWBit(0xB, 0) # Alert 1 Hysteresis - 0xc - _alert_1_hysteresis = UnaryStruct(0xc, ">H") + _alert_1_hysteresis = UnaryStruct(0xC, ">H") # Alert 2 Hysteresis - 0xd - _alert_2_hysteresis = UnaryStruct(0xd, ">H") + _alert_2_hysteresis = UnaryStruct(0xD, ">H") # Alert 3 Hysteresis - 0xe - _alert_3_hysteresis = UnaryStruct(0xe, ">H") + _alert_3_hysteresis = UnaryStruct(0xE, ">H") # Alert 4 Hysteresis - 0xf - _alert_4_hysteresis = UnaryStruct(0xf, ">H") + _alert_4_hysteresis = UnaryStruct(0xF, ">H") # Alert 1 Limit - 0x10 _alert_1_temperature_limit = UnaryStruct(0x10, ">H") # Alert 2 Limit - 0x11 @@ -196,8 +196,17 @@ def __init__(self, i2c, address=_DEFAULT_ADDRESS, tctype="K", tcfilter=0): if self._device_id != 0x40: raise RuntimeError("Failed to find MCP9600 - check wiring!") - def alert_config(self, *, alert_number, alert_temp_source, alert_temp_limit, alert_hysteresis, - alert_temp_direction, alert_mode, alert_state): + def alert_config( + self, + *, + alert_number, + alert_temp_source, + alert_temp_limit, + alert_hysteresis, + alert_temp_direction, + alert_mode, + alert_state + ): """Configure a specified alert pin. Alert is enabled by default when alert is configured. To disable an alert pin, use ``alert_disable``. @@ -250,13 +259,17 @@ def alert_config(self, *, alert_number, alert_temp_source, alert_temp_limit, ale raise ValueError("Alert pin number must be 1-4.") if not 0 <= alert_hysteresis < 256: raise ValueError("Hysteresis value must be 0-255.") - setattr(self, '_alert_%d_monitor' % alert_number, alert_temp_source) - setattr(self, '_alert_%d_temperature_limit' % alert_number, int(alert_temp_limit / 0.0625)) - setattr(self, '_alert_%d_hysteresis' % alert_number, alert_hysteresis) - setattr(self, '_alert_%d_temp_direction' % alert_number, alert_temp_direction) - setattr(self, '_alert_%d_mode' % alert_number, alert_mode) - setattr(self, '_alert_%d_state' % alert_number, alert_state) - setattr(self, '_alert_%d_enable' % alert_number, True) + setattr(self, "_alert_%d_monitor" % alert_number, alert_temp_source) + setattr( + self, + "_alert_%d_temperature_limit" % alert_number, + int(alert_temp_limit / 0.0625), + ) + setattr(self, "_alert_%d_hysteresis" % alert_number, alert_hysteresis) + setattr(self, "_alert_%d_temp_direction" % alert_number, alert_temp_direction) + setattr(self, "_alert_%d_mode" % alert_number, alert_mode) + setattr(self, "_alert_%d_state" % alert_number, alert_state) + setattr(self, "_alert_%d_enable" % alert_number, True) def alert_disable(self, alert_number): """Configuring an alert using ``alert_config()`` enables the specified alert by default. @@ -267,7 +280,7 @@ def alert_disable(self, alert_number): """ if alert_number not in (1, 2, 3, 4): raise ValueError("Alert pin number must be 1-4.") - setattr(self, '_alert_%d_enable' % alert_number, False) + setattr(self, "_alert_%d_enable" % alert_number, False) def alert_interrupt_clear(self, alert_number, interrupt_clear=True): """Turns off the alert flag in the MCP9600, and clears the pin state (not used if the alert @@ -279,7 +292,7 @@ def alert_interrupt_clear(self, alert_number, interrupt_clear=True): """ if alert_number not in (1, 2, 3, 4): raise ValueError("Alert pin number must be 1-4.") - setattr(self, '_alert_%d_interrupt_clear' % alert_number, interrupt_clear) + setattr(self, "_alert_%d_interrupt_clear" % alert_number, interrupt_clear) @property def version(self): @@ -317,10 +330,5 @@ def delta_temperature(self): def _read_register(self, reg, count=1): self.buf[0] = reg with self.i2c_device as i2c: - i2c.write_then_readinto( - self.buf, - self.buf, - out_end=count, - in_start=1 - ) + i2c.write_then_readinto(self.buf, self.buf, out_end=count, in_start=1) return self.buf diff --git a/docs/conf.py b/docs/conf.py index f2379a3..908be15 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", ] # TODO: Please Read! @@ -23,29 +24,32 @@ autodoc_mock_imports = ["adafruit_register"] -intersphinx_mapping = {'python': ('https://docs.python.org/3.4', None),'CircuitPython': ('https://circuitpython.readthedocs.io/en/latest/', None)} +intersphinx_mapping = { + "python": ("https://docs.python.org/3.4", 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 MCP9600 Library' -copyright = u'2019 Dan Cogliano' -author = u'Dan Cogliano' +project = u"Adafruit MCP9600 Library" +copyright = u"2019 Dan Cogliano" +author = u"Dan Cogliano" # 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 +61,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 +73,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 +88,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 = 'AdafruitMcp9600Librarydoc' +htmlhelp_basename = "AdafruitMcp9600Librarydoc" # -- 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, 'AdafruitMCP9600Library.tex', u'AdafruitMCP9600 Library Documentation', - author, 'manual'), + ( + master_doc, + "AdafruitMCP9600Library.tex", + u"AdafruitMCP9600 Library Documentation", + author, + "manual", + ), ] # -- Options for manual page output --------------------------------------- @@ -144,8 +151,13 @@ # One entry per manual page. List of tuples # (source start file, name, description, authors, manual section). man_pages = [ - (master_doc, 'AdafruitMCP9600library', u'Adafruit MCP9600 Library Documentation', - [author], 1) + ( + master_doc, + "AdafruitMCP9600library", + u"Adafruit MCP9600 Library Documentation", + [author], + 1, + ) ] # -- Options for Texinfo output ------------------------------------------- @@ -154,7 +166,13 @@ # (source start file, target name, title, author, # dir menu entry, description, category) texinfo_documents = [ - (master_doc, 'AdafruitMCP9600Library', u'Adafruit MCP9600 Library Documentation', - author, 'AdafruitMCP9600Library', 'One line description of project.', - 'Miscellaneous'), + ( + master_doc, + "AdafruitMCP9600Library", + u"Adafruit MCP9600 Library Documentation", + author, + "AdafruitMCP9600Library", + "One line description of project.", + "Miscellaneous", + ), ] diff --git a/examples/mcp9600_simpletest.py b/examples/mcp9600_simpletest.py index 20d22d9..802be7c 100644 --- a/examples/mcp9600_simpletest.py +++ b/examples/mcp9600_simpletest.py @@ -9,9 +9,5 @@ mcp = adafruit_mcp9600.MCP9600(i2c) while True: - print(( - mcp.ambient_temperature, - mcp.temperature, - mcp.delta_temperature - )) + print((mcp.ambient_temperature, mcp.temperature, mcp.delta_temperature)) time.sleep(1) diff --git a/setup.py b/setup.py index 824abde..d752731 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,54 +14,45 @@ 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-mcp9600', - + name="adafruit-circuitpython-mcp9600", use_scm_version=True, - setup_requires=['setuptools_scm'], - - description='CircuitPython library for the Adafruit MCP9600 breakout', + setup_requires=["setuptools_scm"], + description="CircuitPython library for the Adafruit MCP9600 breakout", 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_MCP9600', - + url="https://github.com/adafruit/Adafruit_CircuitPython_MCP9600", # 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 mcp9600 temp temperature i2c ' - 'thermocouple', - + keywords="adafruit blinka circuitpython micropython mcp9600 temp temperature i2c " + "thermocouple", # 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_mcp9600'], + py_modules=["adafruit_mcp9600"], )