Skip to content

Ran black, updated to pylint 2.x #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
54 changes: 31 additions & 23 deletions adafruit_ina260.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@
from adafruit_register.i2c_bits import RWBits
from adafruit_register.i2c_bit import ROBit

# pylint: disable=bad-whitespace
_REG_CONFIG = const(0x00) # CONFIGURATION REGISTER (R/W)
_REG_CURRENT = const(0x01) # SHUNT VOLTAGE REGISTER (R)
_REG_BUSVOLTAGE = const(0x02) # BUS VOLTAGE REGISTER (R)
_REG_POWER = const(0x03) # POWER REGISTER (R)
_REG_MASK_ENABLE = const(0x06) # MASK ENABLE REGISTER (R/W)
_REG_ALERT_LIMIT = const(0x07) # ALERT LIMIT REGISTER (R/W)
_REG_MFG_UID = const(0xFE) # MANUFACTURER UNIQUE ID REGISTER (R)
_REG_DIE_UID = const(0xFF)# DIE UNIQUE ID REGISTER (R)
# pylint: disable=bad-whitespace
_REG_CONFIG = const(0x00) # CONFIGURATION REGISTER (R/W)
_REG_CURRENT = const(0x01) # SHUNT VOLTAGE REGISTER (R)
_REG_BUSVOLTAGE = const(0x02) # BUS VOLTAGE REGISTER (R)
_REG_POWER = const(0x03) # POWER REGISTER (R)
_REG_MASK_ENABLE = const(0x06) # MASK ENABLE REGISTER (R/W)
_REG_ALERT_LIMIT = const(0x07) # ALERT LIMIT REGISTER (R/W)
_REG_MFG_UID = const(0xFE) # MANUFACTURER UNIQUE ID REGISTER (R)
_REG_DIE_UID = const(0xFF) # DIE UNIQUE ID REGISTER (R)

# pylint: disable=too-few-public-methods
class Mode:
Expand All @@ -86,10 +86,12 @@ class Mode:
+--------------------+---------------------------------------------------------------------+

"""
SHUTDOWN = const(0x0)
TRIGGERED = const(0x3)

SHUTDOWN = const(0x0)
TRIGGERED = const(0x3)
CONTINUOUS = const(0x7)


class ConversionTime:
"""Options for ``current_conversion_time`` or ``voltage_conversion_time``

Expand All @@ -114,15 +116,17 @@ class ConversionTime:
+----------------------------------+------------------+

"""
TIME_140_us = const(0x0)
TIME_204_us = const(0x1)
TIME_332_us = const(0x2)
TIME_558_us = const(0x3)
TIME_1_1_ms = const(0x4)

TIME_140_us = const(0x0)
TIME_204_us = const(0x1)
TIME_332_us = const(0x2)
TIME_558_us = const(0x3)
TIME_1_1_ms = const(0x4)
TIME_2_116_ms = const(0x5)
TIME_4_156_ms = const(0x6)
TIME_8_244_ms = const(0x7)


class AveragingCount:
"""Options for ``averaging_count``

Expand All @@ -147,17 +151,21 @@ class AveragingCount:
+-------------------------------+------------------------------------+

"""
COUNT_1 = const(0x1)
COUNT_4 = const(0x2)
COUNT_16 = const(0x3)
COUNT_64 = const(0x4)
COUNT_128 = const(0x5)
COUNT_256 = const(0x6)
COUNT_512 = const(0x7)

COUNT_1 = const(0x1)
COUNT_4 = const(0x2)
COUNT_16 = const(0x3)
COUNT_64 = const(0x4)
COUNT_128 = const(0x5)
COUNT_256 = const(0x6)
COUNT_512 = const(0x7)
COUNT_1024 = const(0x8)


# pylint: enable=bad-whitespace
# pylint: enable=too-few-public-methods


class INA260:
"""Driver for the INA260 power and current sensor.

Expand Down
127 changes: 79 additions & 48 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,67 @@

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!
# Uncomment the below if you use native CircuitPython modules such as
# digitalio, micropython and busio. List the modules you use. Without it, the
# autodoc module docs will fail to generate with a warning.
autodoc_mock_imports = ["micropython", "busio", "adafruit_bus_device", "adafruit_register"]
autodoc_mock_imports = [
"micropython",
"busio",
"adafruit_bus_device",
"adafruit_register",
]


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 INA260 Library'
copyright = u'2019 Bryan Siepert'
author = u'Bryan Siepert'
project = u"Adafruit INA260 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.
Expand All @@ -57,7 +74,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 +86,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 +101,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 = 'AdafruitIna260Librarydoc'
htmlhelp_basename = "AdafruitIna260Librarydoc"

# -- 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, 'AdafruitINA260Library.tex', u'AdafruitINA260 Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitINA260Library.tex",
u"AdafruitINA260 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, 'AdafruitINA260library', u'Adafruit INA260 Library Documentation',
[author], 1)
(
master_doc,
"AdafruitINA260library",
u"Adafruit INA260 Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -154,7 +179,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitINA260Library', u'Adafruit INA260 Library Documentation',
author, 'AdafruitINA260Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitINA260Library",
u"Adafruit INA260 Library Documentation",
author,
"AdafruitINA260Library",
"One line description of project.",
"Miscellaneous",
),
]
6 changes: 3 additions & 3 deletions examples/ina260_averaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
# Raise the averaging count to a larger number to smooth out the results
ina260.averaging_count = AveragingCount.COUNT_4
while True:
print("Current (average count 4): %.2f"%(ina260.current))
print("Voltage (average count 4): %.2f"%(ina260.voltage))
print("Power (average count 4): %.2f"%(ina260.power))
print("Current (average count 4): %.2f" % (ina260.current))
print("Voltage (average count 4): %.2f" % (ina260.voltage))
print("Power (average count 4): %.2f" % (ina260.power))

time.sleep(1)

Expand Down
30 changes: 15 additions & 15 deletions examples/ina260_modes.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,33 @@

# trigger a sample
ina260.mode = Mode.TRIGGERED
print("Current (one shot #1): %.2f"%(ina260.current))
print("Voltage (one shot #1): %.2f"%(ina260.voltage))
print("Power (one shot #1): %.2f"%(ina260.power))
print("Current (one shot #1): %.2f" % (ina260.current))
print("Voltage (one shot #1): %.2f" % (ina260.voltage))
print("Power (one shot #1): %.2f" % (ina260.power))

# print it again to show it will return the same value
# until triggered again
print("Current (one shot #1 redux): %.2f"%(ina260.current))
print("Voltage (one shot #1 redux): %.2f"%(ina260.voltage))
print("Power (one shot #1 redux): %.2f"%(ina260.power))
print("Current (one shot #1 redux): %.2f" % (ina260.current))
print("Voltage (one shot #1 redux): %.2f" % (ina260.voltage))
print("Power (one shot #1 redux): %.2f" % (ina260.power))

# trigger a second sample
ina260.mode = Mode.TRIGGERED
print("Current (one shot #2): %.2f"%(ina260.current))
print("Voltage (one shot #2): %.2f"%(ina260.voltage))
print("Power (one shot #2): %.2f"%(ina260.power))
print("Current (one shot #2): %.2f" % (ina260.current))
print("Voltage (one shot #2): %.2f" % (ina260.voltage))
print("Power (one shot #2): %.2f" % (ina260.power))

# put the sensor in power-down mode. It will return
# the previous value until a new mode is chosen
ina260.mode = Mode.SHUTDOWN
print("Current (shutdown): %.2f"%(ina260.current))
print("Voltage (shutdown): %.2f"%(ina260.voltage))
print("Power (shutdown): %.2f"%(ina260.power))
print("Current (shutdown): %.2f" % (ina260.current))
print("Voltage (shutdown): %.2f" % (ina260.voltage))
print("Power (shutdown): %.2f" % (ina260.power))

# return the sensor to the default continuous mode
ina260.mode = Mode.CONTINUOUS
while True:
print("Current (continuous): %.2f"%(ina260.current))
print("Voltage (continuous): %.2f"%(ina260.voltage))
print("Power (continuous): %.2f"%(ina260.power))
print("Current (continuous): %.2f" % (ina260.current))
print("Voltage (continuous): %.2f" % (ina260.voltage))
print("Power (continuous): %.2f" % (ina260.power))
time.sleep(1)
6 changes: 4 additions & 2 deletions examples/ina260_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
i2c = board.I2C()
ina260 = adafruit_ina260.INA260(i2c)
while True:
print("Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
%(ina260.current, ina260.voltage, ina260.power))
print(
"Current: %.2f mA Voltage: %.2f V Power:%.2f mW"
% (ina260.current, ina260.voltage, ina260.power)
)
time.sleep(1)
Loading