Skip to content

Ran black, updated to pylint 2.x #9

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 16, 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
31 changes: 14 additions & 17 deletions adafruit_vcnl4040.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class VCNL4040: # pylint: disable=too-few-public-methods
:param busio.I2C i2c_bus: The I2C bus the VCNL4040 is connected to.

"""

# Ambient light sensor integration times
ALS_80MS = const(0x0)
ALS_160MS = const(0x1)
Expand Down Expand Up @@ -169,7 +170,6 @@ def proximity_low_interrupt(self):
proximity drops below low threshold."""
return self._get_and_clear_cached_interrupt_state(self.PS_IF_AWAY)


led_current = RWBits(3, 0x04, 8, register_width=2)
"""LED current selection setting, in mA. Options are LED_50MA, LED_75MA, LED_100MA, LED_120MA,
LED_140MA, LED_160MA, LED_180MA, LED_200MA."""
Expand Down Expand Up @@ -205,14 +205,14 @@ def lux(self):
print("Ambient light: %.2f lux"%sensor.lux)
time.sleep(0.1)
"""
return self.light * (0.1 /(1 << self.light_integration_time))

return self.light * (0.1 / (1 << self.light_integration_time))

# ALS_CONF - ALS integration time, persistence, interrupt, function enable/disable
light_shutdown = RWBit(0x00, 0, register_width=2)
"""Ambient light sensor shutdown. When ``True``, ambient light data is disabled."""

_light_integration_time = RWBits(2, 0x00, 6, register_width=2)

@property
def light_integration_time(self):
"""Ambient light sensor integration time setting. Longer time has higher sensitivity.
Expand Down Expand Up @@ -240,16 +240,16 @@ def light_integration_time(self):

@light_integration_time.setter
def light_integration_time(self, new_it):
from time import sleep
from time import sleep # pylint: disable=import-outside-toplevel

# IT values are in 0-3 -> 80-640ms
old_it_ms = ((8<< self._light_integration_time)*10)
new_it_ms = ((8<< new_it)*10)
old_it_ms = (8 << self._light_integration_time) * 10
new_it_ms = (8 << new_it) * 10
it_delay_seconds = (old_it_ms + new_it_ms + 1) * 0.001

self._light_integration_time = new_it
sleep(it_delay_seconds)


light_interrupt = RWBit(0x00, 1, register_width=2)
"""Ambient light sensor interrupt enable. ``True`` to enable, and ``False`` to disable."""

Expand All @@ -271,10 +271,9 @@ def light_low_interrupt(self):
"""Low interrupt event. Triggered when ambient light value drops below low threshold."""
return self._get_and_clear_cached_interrupt_state(self.ALS_IF_L)


_raw_white = ROUnaryStruct(0x0A, "<H")
@property

@property
def white(self):
"""White light data scaled according to the current integration time and gain settings.

Expand All @@ -294,25 +293,23 @@ def white(self):
print("White light:", sensor.white)
time.sleep(0.1)
"""
return self._raw_white * (0.1 /(1 << self.light_integration_time))

return self._raw_white * (0.1 / (1 << self.light_integration_time))

# PS_MS - White channel enable/disable, PS mode, PS protection setting, LED current
# White_EN - PS_MS_H, 7th bit - White channel enable/disable
white_shutdown = RWBit(0x04, 15, register_width=2)
"""White light channel shutdown. When ``True``, white light data is disabled."""


def __init__(self, i2c, address=0x60):
self.i2c_device = i2cdevice.I2CDevice(i2c, address)
if self._device_id != 0x186:
raise RuntimeError("Failed to find VCNL4040 - check wiring!")

self.cached_interrupt_state = {
self.ALS_IF_L : False,
self.ALS_IF_H : False,
self.PS_IF_CLOSE : False,
self.PS_IF_AWAY : False
self.ALS_IF_L: False,
self.ALS_IF_H: False,
self.PS_IF_CLOSE: False,
self.PS_IF_AWAY: False,
}

self.proximity_shutdown = False
Expand All @@ -323,7 +320,7 @@ def _update_interrupt_state(self):
interrupts = [self.PS_IF_AWAY, self.PS_IF_CLOSE, self.ALS_IF_H, self.ALS_IF_L]
new_interrupt_state = self.interrupt_state
for interrupt in interrupts:
new_state = (new_interrupt_state & (1 << interrupt) > 0)
new_state = new_interrupt_state & (1 << interrupt) > 0
if new_state:
self.cached_interrupt_state[interrupt] = new_state

Expand Down
130 changes: 81 additions & 49 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,69 @@

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 = ["adafruit_register.i2c_struct", "adafruit_register.i2c_bits",
"adafruit_register.i2c_bit", "micropython", "adafruit_bus_device", "adafruit_register"]
autodoc_mock_imports = [
"adafruit_register.i2c_struct",
"adafruit_register.i2c_bits",
"adafruit_register.i2c_bit",
"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),'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 VCNL4040 Library'
copyright = u'2019 Kattni Rembor'
author = u'Kattni Rembor'
project = u"Adafruit VCNL4040 Library"
copyright = u"2019 Kattni Rembor"
author = u"Kattni Rembor"

# 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 @@ -58,7 +76,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 @@ -70,7 +88,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 @@ -85,68 +103,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 = 'AdafruitVcnl4040Librarydoc'
htmlhelp_basename = "AdafruitVcnl4040Librarydoc"

# -- 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, 'AdafruitVCNL4040Library.tex', u'AdafruitVCNL4040 Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitVCNL4040Library.tex",
u"AdafruitVCNL4040 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, 'AdafruitVCNL4040library', u'Adafruit VCNL4040 Library Documentation',
[author], 1)
(
master_doc,
"AdafruitVCNL4040library",
u"Adafruit VCNL4040 Library Documentation",
[author],
1,
)
]

# -- Options for Texinfo output -------------------------------------------
Expand All @@ -155,7 +181,13 @@
# (source start file, target name, title, author,
# dir menu entry, description, category)
texinfo_documents = [
(master_doc, 'AdafruitVCNL4040Library', u'Adafruit VCNL4040 Library Documentation',
author, 'AdafruitVCNL4040Library', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitVCNL4040Library",
u"Adafruit VCNL4040 Library Documentation",
author,
"AdafruitVCNL4040Library",
"One line description of project.",
"Miscellaneous",
),
]
2 changes: 1 addition & 1 deletion examples/vcnl4040_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@

while True:
print("Proximity:", sensor.proximity)
print("Light: %d lux"% sensor.lux)
print("Light: %d lux" % sensor.lux)
time.sleep(1.0)
Loading