Skip to content

Ran black, updated to pylint 2.x #40

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
3 changes: 2 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,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]
Expand Down
56 changes: 34 additions & 22 deletions adafruit_ccs811.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@
_HW_ID_CODE = const(0x81)
_REF_RESISTOR = const(100000)


class CCS811:
"""CCS811 gas sensor driver.

:param ~busio.I2C i2c: The I2C bus.
:param int addr: The I2C address of the CCS811.
"""
#set up the registers

# set up the registers
error = i2c_bit.ROBit(0x00, 0)
"""True when an error has occured."""
data_ready = i2c_bit.ROBit(0x00, 3)
Expand All @@ -99,32 +101,38 @@ class CCS811:
def __init__(self, i2c_bus, address=0x5A):
self.i2c_device = I2CDevice(i2c_bus, address)

#check that the HW id is correct
# check that the HW id is correct
if self.hw_id != _HW_ID_CODE:
raise RuntimeError("Device ID returned is not correct! Please check your wiring.")
raise RuntimeError(
"Device ID returned is not correct! Please check your wiring."
)

#try to start the app
# try to start the app
buf = bytearray(1)
buf[0] = 0xF4
with self.i2c_device as i2c:
i2c.write(buf, end=1)
time.sleep(.1)
time.sleep(0.1)

#make sure there are no errors and we have entered application mode
# make sure there are no errors and we have entered application mode
if self.error:
raise RuntimeError("Device returned a error! Try removing and reapplying power to "
"the device and running the code again.")
raise RuntimeError(
"Device returned a error! Try removing and reapplying power to "
"the device and running the code again."
)
if not self.fw_mode:
raise RuntimeError("Device did not enter application mode! If you got here, there may "
"be a problem with the firmware on your sensor.")
raise RuntimeError(
"Device did not enter application mode! If you got here, there may "
"be a problem with the firmware on your sensor."
)

self.interrupt_enabled = False

#default to read every second
# default to read every second
self.drive_mode = DRIVE_MODE_1SEC

self._eco2 = None # pylint: disable=invalid-name
self._tvoc = None # pylint: disable=invalid-name
self._eco2 = None # pylint: disable=invalid-name
self._tvoc = None # pylint: disable=invalid-name

@property
def error_code(self):
Expand All @@ -149,13 +157,13 @@ def _update_data(self):
raise RuntimeError("Error:" + str(self.error_code))

@property
def tvoc(self): # pylint: disable=invalid-name
def tvoc(self): # pylint: disable=invalid-name
"""Total Volatile Organic Compound in parts per billion."""
self._update_data()
return self._tvoc

@property
def eco2(self): # pylint: disable=invalid-name
def eco2(self): # pylint: disable=invalid-name
"""Equivalent Carbon Dioxide in parts per million. Clipped to 400 to 8192ppm."""
self._update_data()
return self._eco2
Expand Down Expand Up @@ -216,18 +224,22 @@ def set_interrupt_thresholds(self, low_med, med_high, hysteresis):
:param int low_med: Boundary between low and medium ranges
:param int med_high: Boundary between medium and high ranges
:param int hysteresis: Minimum difference between reads"""
buf = bytearray([_THRESHOLDS,
((low_med >> 8) & 0xF),
(low_med & 0xF),
((med_high >> 8) & 0xF),
(med_high & 0xF),
hysteresis])
buf = bytearray(
[
_THRESHOLDS,
((low_med >> 8) & 0xF),
(low_med & 0xF),
((med_high >> 8) & 0xF),
(med_high & 0xF),
hysteresis,
]
)
with self.i2c_device as i2c:
i2c.write(buf)

def reset(self):
"""Initiate a software reset."""
#reset sequence from the datasheet
# reset sequence from the datasheet
seq = bytearray([_SW_RESET, 0x11, 0xE5, 0x72, 0x8A])
with self.i2c_device as i2c:
i2c.write(seq)
130 changes: 77 additions & 53 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
#
import os
import sys
sys.path.insert(0, os.path.abspath('..'))

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

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

Expand All @@ -30,54 +31,61 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.todo',
'sphinx.ext.viewcode',
'sphinx.ext.intersphinx'
"sphinx.ext.autodoc",
"sphinx.ext.todo",
"sphinx.ext.viewcode",
"sphinx.ext.intersphinx",
]

# 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", "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),'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,
),
"CircuitPython": ("https://circuitpython.readthedocs.io/en/latest/", None),
}

# Mock out micropython ourselves.
#import imp
#m = imp.new_module("micropython")
#m.const = lambda x: x
#sys.modules["micropython"] = m
# import imp
# m = imp.new_module("micropython")
# m.const = lambda x: x
# sys.modules["micropython"] = m

# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
templates_path = ["_templates"]

# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
#source_suffix = ['.rst', '.md']
source_suffix = '.rst'
# source_suffix = ['.rst', '.md']
source_suffix = ".rst"

# The encoding of source files.
#
# source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
master_doc = "index"

# General information about the project.
project = u'Adafruit\'s CCS811 Library'
copyright = u'2016, Dean Miller, Scott Shawcroft'
author = u'Dean Miller, Scott Shawcroft'
project = u"Adafruit's CCS811 Library"
copyright = u"2016, Dean Miller, Scott Shawcroft"
author = u"Dean Miller, Scott Shawcroft"

# 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 @@ -98,7 +106,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 @@ -120,7 +128,7 @@
# show_authors = False

# The name of the Pygments (syntax highlighting) style to use.
pygments_style = 'sphinx'
pygments_style = "sphinx"

# A list of ignored prefixes for module index sorting.
# modindex_common_prefix = []
Expand All @@ -140,18 +148,19 @@
# 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 = ["."]

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down Expand Up @@ -185,13 +194,13 @@
# 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"

# Add any extra paths that contain custom files (such as robots.txt or
# .htaccess) here, relative to this directory. These files are copied
Expand Down Expand Up @@ -276,29 +285,31 @@
# -- 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, 'AdafruitsCCS811Library.tex', u'Adafruit\'s CCS811 Library Documentation',
u'Dean Miller, Scott Shawcroft', 'manual'),
(
master_doc,
"AdafruitsCCS811Library.tex",
u"Adafruit's CCS811 Library Documentation",
u"Dean Miller, Scott Shawcroft",
"manual",
),
]

# The name of an image file (relative to this directory) to place at the top of
Expand Down Expand Up @@ -339,8 +350,13 @@
# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
(master_doc, 'AdafruitsCCS811Library23library', u'Adafruit\'s CCS811 Library Documentation',
[author], 1)
(
master_doc,
"AdafruitsCCS811Library23library",
u"Adafruit's CCS811 Library Documentation",
[author],
1,
)
]

# If true, show URL addresses after external links.
Expand All @@ -354,9 +370,15 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitsCCS811Library', u'Adafruit\'s CCS811 Library Documentation',
author, 'AdafruitsCCS811Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitsCCS811Library",
u"Adafruit's CCS811 Library Documentation",
author,
"AdafruitsCCS811Library",
"One line description of project.",
"Miscellaneous",
),
]

# Documents to append as an appendix to all manuals.
Expand All @@ -375,5 +397,7 @@
#
# texinfo_no_detailmenu = False

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),
}
3 changes: 1 addition & 2 deletions examples/ccs811_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
pass

while True:
print("CO2: {} PPM, TVOC: {} PPB"
.format(ccs811.eco2, ccs811.tvoc))
print("CO2: {} PPM, TVOC: {} PPB".format(ccs811.eco2, ccs811.tvoc))
time.sleep(0.5)
Loading