Skip to content

Commit

Permalink
Merge pull request #12 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Ran black, updated to pylint 2.x
  • Loading branch information
kattni authored Mar 16, 2020
2 parents 450c758 + 2de0c7b commit 3f22176
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
74 changes: 41 additions & 33 deletions adafruit_mcp9600.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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``.
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
112 changes: 65 additions & 47 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

sys.path.insert(0, os.path.abspath(".."))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# 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!
Expand All @@ -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.
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -84,68 +88,76 @@
# 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 ---------------------------------------

# 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 -------------------------------------------
Expand All @@ -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",
),
]
6 changes: 1 addition & 5 deletions examples/mcp9600_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading

0 comments on commit 3f22176

Please sign in to comment.