Skip to content

Commit

Permalink
Merge pull request #36 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 17, 2020
2 parents 525c273 + 2dc7d0b commit 0111721
Show file tree
Hide file tree
Showing 13 changed files with 329 additions and 267 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
236 changes: 130 additions & 106 deletions adafruit_espatcontrol/adafruit_espatcontrol.py

Large diffs are not rendered by default.

36 changes: 23 additions & 13 deletions adafruit_espatcontrol/adafruit_espatcontrol_socket.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
"""A 'socket' compatible interface thru the ESP AT command set"""
from micropython import const

_the_interface = None # pylint: disable=invalid-name
_the_interface = None # pylint: disable=invalid-name


def set_interface(iface):
"""Helper to set the global internet interface"""
global _the_interface # pylint: disable=global-statement, invalid-name
global _the_interface # pylint: disable=global-statement, invalid-name
_the_interface = iface


SOCK_STREAM = const(1)
AF_INET = const(2)

Expand All @@ -17,42 +20,46 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
if not isinstance(port, int):
raise RuntimeError("port must be an integer")
ipaddr = _the_interface.nslookup(host)
return [(AF_INET, socktype, proto, '', (ipaddr, port))]
return [(AF_INET, socktype, proto, "", (ipaddr, port))]


# pylint: enable=too-many-arguments, unused-argument


# pylint: disable=unused-argument, redefined-builtin, invalid-name
class socket:
"""A simplified implementation of the Python 'socket' class, for connecting
through an interface to a remote device"""

def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
if family != AF_INET:
raise RuntimeError("Only AF_INET family supported")
if type != SOCK_STREAM:
raise RuntimeError("Only SOCK_STREAM type supported")
self._buffer = b''
self._buffer = b""
self.settimeout(0)

def connect(self, address, conntype=None):
"""Connect the socket to the 'address' (which should be dotted quad IP). 'conntype'
is an extra that may indicate SSL or not, depending on the underlying interface"""
host, port = address
if not _the_interface.socket_connect(conntype, host, port, keepalive=10, retries=3):
if not _the_interface.socket_connect(
conntype, host, port, keepalive=10, retries=3
):
raise RuntimeError("Failed to connect to host", host)
self._buffer = b''
self._buffer = b""


def send(self, data): # pylint: disable=no-self-use
def send(self, data): # pylint: disable=no-self-use
"""Send some data to the socket"""
_the_interface.socket_send(data)

def readline(self):
"""Attempt to return as many bytes as we can up to but not including '\r\n'"""
if b'\r\n' not in self._buffer:
if b"\r\n" not in self._buffer:
# there's no line already in there, read some more
self._buffer = self._buffer + _the_interface.socket_receive(timeout=3)
#print(self._buffer)
firstline, self._buffer = self._buffer.split(b'\r\n', 1)
# print(self._buffer)
firstline, self._buffer = self._buffer.split(b"\r\n", 1)
return firstline

def recv(self, num=0):
Expand All @@ -61,7 +68,7 @@ def recv(self, num=0):
if num == 0:
# read as much as we can
ret = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
self._buffer = b''
self._buffer = b""
else:
ret = self._buffer[:num]
self._buffer = self._buffer[num:]
Expand All @@ -70,11 +77,14 @@ def recv(self, num=0):
def close(self):
"""Close the socket, after reading whatever remains"""
# read whatever's left
self._buffer = self._buffer + _the_interface.socket_receive(timeout=self._timeout)
self._buffer = self._buffer + _the_interface.socket_receive(
timeout=self._timeout
)
_the_interface.socket_disconnect()

def settimeout(self, value):
"""Set the read timeout for sockets, if value is 0 it will block"""
self._timeout = value


# pylint: enable=unused-argument, redefined-builtin, invalid-name
2 changes: 2 additions & 0 deletions adafruit_espatcontrol/adafruit_espatcontrol_wifimanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,12 @@
import adafruit_espatcontrol.adafruit_espatcontrol_socket as socket
import adafruit_requests as requests


class ESPAT_WiFiManager:
"""
A class to help manage the Wifi connection
"""

def __init__(self, esp, secrets, status_pixel=None, attempts=2):
"""
:param ESP_SPIcontrol esp: The ESP object we are using
Expand Down
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 = ["digitalio", "busio"]


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 espATcontrol Library'
copyright = u'2018 ladyada'
author = u'ladyada'
project = u"Adafruit espATcontrol Library"
copyright = u"2018 ladyada"
author = u"ladyada"

# 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 = 'AdafruitEspatcontrolLibrarydoc'
htmlhelp_basename = "AdafruitEspatcontrolLibrarydoc"

# -- 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, 'AdafruitespATcontrolLibrary.tex', u'AdafruitespATcontrol Library Documentation',
author, 'manual'),
(
master_doc,
"AdafruitespATcontrolLibrary.tex",
u"AdafruitespATcontrol 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, 'AdafruitespATcontrollibrary', u'Adafruit espATcontrol Library Documentation',
[author], 1)
(
master_doc,
"AdafruitespATcontrollibrary",
u"Adafruit espATcontrol 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, 'AdafruitespATcontrolLibrary', u'Adafruit espATcontrol Library Documentation',
author, 'AdafruitespATcontrolLibrary', 'One line description of project.',
'Miscellaneous'),
(
master_doc,
"AdafruitespATcontrolLibrary",
u"Adafruit espATcontrol Library Documentation",
author,
"AdafruitespATcontrolLibrary",
"One line description of project.",
"Miscellaneous",
),
]
26 changes: 17 additions & 9 deletions examples/esp_atcontrol_aio_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from digitalio import Direction

# ESP32 AT
from adafruit_espatcontrol import adafruit_espatcontrol, adafruit_espatcontrol_wifimanager

from adafruit_espatcontrol import (
adafruit_espatcontrol,
adafruit_espatcontrol_wifimanager,
)


# Get wifi details and more from a secrets.py file
Expand All @@ -29,23 +31,29 @@
status_light = None

print("ESP AT commands")
esp = adafruit_espatcontrol.ESP_ATcontrol(uart, 115200,
reset_pin=resetpin, rts_pin=rtspin, debug=False)
esp = adafruit_espatcontrol.ESP_ATcontrol(
uart, 115200, reset_pin=resetpin, rts_pin=rtspin, debug=False
)
wifi = adafruit_espatcontrol_wifimanager.ESPAT_WiFiManager(esp, secrets, status_light)


counter = 0

while True:
try:
print("Posting data...", end='')
print("Posting data...", end="")
data = counter
feed = 'test'
payload = {'value':data}
feed = "test"
payload = {"value": data}
response = wifi.post(
"https://io.adafruit.com/api/v2/"+secrets['aio_username']+"/feeds/"+feed+"/data",
"https://io.adafruit.com/api/v2/"
+ secrets["aio_username"]
+ "/feeds/"
+ feed
+ "/data",
json=payload,
headers={"X-AIO-KEY":secrets['aio_key']})
headers={"X-AIO-KEY": secrets["aio_key"]},
)
print(response.json())
response.close()
counter = counter + 1
Expand Down
Loading

0 comments on commit 0111721

Please sign in to comment.