Skip to content

Commit

Permalink
Merge pull request #8 from adafruit/pylint-update
Browse files Browse the repository at this point in the history
Pylint update
  • Loading branch information
kattni committed Mar 9, 2020
2 parents 70c79ab + 49cf2f7 commit 7af47da
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 123 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 pylint black==19.10b0 Sphinx sphinx-rtd-theme
- name: Library version
run: git describe --dirty --always --tags
- name: PyLint
Expand Down
42 changes: 28 additions & 14 deletions adafruit_aws_iot.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@

class AWS_IOT_ERROR(Exception):
"""Exception raised on MQTT API return-code errors."""

# pylint: disable=unnecessary-pass
pass


class MQTT_CLIENT:
"""Client for interacting with Amazon AWS IoT MQTT API.
Expand All @@ -60,24 +62,33 @@ class MQTT_CLIENT:
Provided interval must be 30 <= keep_alive <= 1200.
"""

def __init__(self, mmqttclient, keep_alive=30):
if "MQTT" in str(type(mmqttclient)):
self.client = mmqttclient
else:
raise TypeError("This class requires a preconfigured MiniMQTT object, \
please create one.")
raise TypeError(
"This class requires a preconfigured MiniMQTT object, \
please create one."
)
# Verify MiniMQTT client object configuration
try:
self.cid = self.client.client_id
assert self.cid[0] != "$", "Client ID can not start with restricted client ID prefix $."
assert (
self.cid[0] != "$"
), "Client ID can not start with restricted client ID prefix $."
except:
raise TypeError("You must provide MiniMQTT with your AWS IoT Device's Identifier \
as the Client ID.")
raise TypeError(
"You must provide MiniMQTT with your AWS IoT Device's Identifier \
as the Client ID."
)
# Shadow-interaction topic
self.shadow_topic = "$aws/things/{}/shadow".format(self.cid)
# keep_alive timer must be between 30 <= keep alive interval <= 1200 seconds
# https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html
assert 30 <= keep_alive <= 1200, "Keep_Alive timer \
assert (
30 <= keep_alive <= 1200
), "Keep_Alive timer \
interval must be between 30 and 1200 seconds"
self.keep_alive = keep_alive
# User-defined MQTT callback methods must be init'd to None
Expand All @@ -100,7 +111,6 @@ def __enter__(self):
def __exit__(self, exception_type, exception_value, traceback):
self.disconnect()


@property
def is_connected(self):
"""Returns if MQTT_CLIENT is connected to AWS IoT MQTT Broker
Expand All @@ -115,7 +125,7 @@ def disconnect(self):
try:
self.client.disconnect()
except MMQTTException as error:
raise AWS_IOT_ERROR('Error disconnecting with AWS IoT: ', error)
raise AWS_IOT_ERROR("Error disconnecting with AWS IoT: ", error)
self.connected_to_aws = False
# Reset user-defined callback methods to None
self.on_connect = None
Expand All @@ -133,7 +143,7 @@ def connect(self, clean_session=True):
try:
self.client.connect(clean_session)
except MMQTTException as error:
raise AWS_IOT_ERROR('Error connecting to AWS IoT: ', error)
raise AWS_IOT_ERROR("Error connecting to AWS IoT: ", error)
self.connected_to_aws = True

# MiniMQTT Callback Handlers
Expand Down Expand Up @@ -265,30 +275,34 @@ def shadow_get_subscribe(self, qos=1):
:param int qos: Optional quality of service level.
"""
self.client.subscribe(self.shadow_topic+"/get/#", qos)
self.client.subscribe(self.shadow_topic + "/get/#", qos)

def shadow_subscribe(self, qos=1):
"""Subscribes to all notifications on the device's shadow update topic.
:param int qos: Optional quality of service level.
"""
self.client.subscribe(self.shadow_topic+"/update/#", qos)
self.client.subscribe(self.shadow_topic + "/update/#", qos)

def shadow_update(self, document):
"""Publishes a request state document to update the device's shadow.
:param json state_document: JSON-formatted state document.
"""
self.client.publish(self.shadow_topic+"/update", document)
self.client.publish(self.shadow_topic + "/update", document)

def shadow_get(self):
"""Publishes an empty message to shadow get topic to get the device's shadow.
"""
self.client.publish(self.shadow_topic+"/get", json.dumps({"message": "ignore"}))
self.client.publish(
self.shadow_topic + "/get", json.dumps({"message": "ignore"})
)

def shadow_delete(self):
"""Publishes an empty message to the shadow delete topic to delete a device's shadow
"""
self.client.publish(self.shadow_topic+"/delete", json.dumps({"message": "delete"}))
self.client.publish(
self.shadow_topic + "/delete", json.dumps({"message": "delete"})
)
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_minimqtt"]


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 AWS_IOT Library'
copyright = u'2019 Brent Rubell'
author = u'Brent Rubell'
project = "Adafruit AWS_IOT Library"
copyright = "2019 Brent Rubell"
author = "Brent Rubell"

# 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 = "1.0"
# The full version, including alpha/beta/rc tags.
release = u'1.0'
release = "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 = 'AdafruitAws_iotLibrarydoc'
htmlhelp_basename = "AdafruitAws_iotLibrarydoc"

# -- 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, 'AdafruitAWS_IOTLibrary.tex', u'AdafruitAWS_IOT Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitAWS_IOTLibrary.tex",
"AdafruitAWS_IOT 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, 'AdafruitAWS_IOTlibrary', u'Adafruit AWS_IOT Library Documentation',
[author], 1)
(
master_doc,
"AdafruitAWS_IOTlibrary",
"Adafruit AWS_IOT 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, 'AdafruitAWS_IOTLibrary', u'Adafruit AWS_IOT Library Documentation',
author, 'AdafruitAWS_IOTLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitAWS_IOTLibrary",
"Adafruit AWS_IOT Library Documentation",
author,
"AdafruitAWS_IOTLibrary",
"One line description of project.",
"Miscellaneous",
),
]

0 comments on commit 7af47da

Please sign in to comment.