Skip to content

Commit 475dd5e

Browse files
committed
adjust README; add CONTRIBUTING guide
and some additional tweaks to the docs...
1 parent c41dd21 commit 475dd5e

File tree

8 files changed

+154
-33
lines changed

8 files changed

+154
-33
lines changed

CONTRIBUTING.rst

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
2+
Contributing Guidelines
3+
=======================
4+
5+
Building the Documentation
6+
--------------------------
7+
8+
To build library documentation, you need to install Graphviz and the documentation dependencies.
9+
10+
.. code-block:: shell
11+
12+
pip install -r docs/requirements.txt
13+
14+
.. note::
15+
Installing graphviz differs depending on your platform.
16+
17+
Linux users can simply,
18+
19+
.. code-block:: shell
20+
21+
sudo apt-get install graphviz
22+
23+
Windows users will have to install the binaries from
24+
`the official Graphviz downloads <https://graphviz.org/download/#windows>`_. Just be sure that
25+
the installed ``bin`` folder is added to your environment's PATH variable.
26+
27+
Finally, build the documentation with Sphinx:
28+
29+
.. code-block:: shell
30+
31+
sphinx-build -E -W docs docs/_build/html
32+
33+
The rendered HTML files should now be located in the ``docs/_build/html`` folder. Point your
34+
internet browser to this path and check the changes have been rendered properly.
35+
36+
Linting the source code
37+
-----------------------
38+
39+
.. _pre-commit: https://pre-commit.com/
40+
41+
This library uses pre-commit_ for some linting tools like
42+
43+
- `black <https://black.readthedocs.io/en/stable/>`_
44+
- `pylint <https://pylint.pycqa.org/en/stable/>`_
45+
- `mypy <https://mypy.readthedocs.io/en/stable/>`_
46+
47+
To use pre-commit_, you must install it and create the cached environments that it needs.
48+
49+
.. code-block:: shell
50+
51+
pip install pre-commit
52+
pre-commit install
53+
54+
Now, every time you commit something it will run pre-commit_ on the changed files. You can also
55+
run pre-commit_ on staged files:
56+
57+
.. code-block:: shell
58+
59+
pre-commit run
60+
61+
Testing the source code
62+
-----------------------
63+
64+
.. _pytest: https://docs.pytest.org/en/latest/
65+
.. _coverage: https://coverage.readthedocs.io/en/latest/
66+
67+
Code coverage/testing is done with pytest_ and coverage_ libraries. Install these tools (and
68+
this library's dependencies) with:
69+
70+
.. code-block:: shell
71+
72+
pip install -r test/requirements.txt -r requirements.txt
73+
74+
Run the tests and collect the code coverage with:
75+
76+
.. code-block:: shell
77+
78+
coverage run -m pytest

README.rst

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Introduction
33

44

55
.. image:: https://readthedocs.org/projects/circuitpython-homie/badge/?version=latest
6-
:target: https://circuitpython-homie.readthedocs.io/
6+
:target: https://circuitpython-homie.rtfd.io/
77
:alt: Documentation Status
88
.. image:: https://github.com/2bndy5/CircuitPython_Homie/workflows/Build%20CI/badge.svg
99
:target: https://github.com/2bndy5/CircuitPython_Homie/actions
@@ -20,27 +20,24 @@ Homie specifications for MQTT implemented in CircuitPython
2020
:width: 50%
2121

2222
Dependencies
23-
=============
23+
------------
24+
2425
This driver depends on:
2526

2627
* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
28+
* `Adafruit MiniMQTT Library <https://docs.circuitpython.org/projects/minimqtt/en/latest/>`_
2729

2830
Please ensure all dependencies are available on the CircuitPython filesystem.
2931
This is easily achieved by downloading
3032
`the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_
31-
or individual libraries can be installed using
32-
`circup <https://github.com/adafruit/circup>`_.
33+
or individual libraries can be installed using `circup <https://github.com/adafruit/circup>`_.
3334

3435
Installing from PyPI
35-
=====================
36-
37-
.. note::
38-
This library is not available on PyPI yet. Install documentation is included
39-
as a standard element. Stay tuned for PyPI availability!
36+
--------------------
4037

41-
.. admonition:: todo
38+
.. code-block:: shell
4239
43-
Remove the above note if PyPI version is/will be available at time of release.
40+
pip install circuitpython-homie
4441
4542
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
4643
PyPI <https://pypi.org/project/circuitpython-homie/>`_.
@@ -61,12 +58,12 @@ To install in a virtual environment in your current project:
6158
.. code-block:: shell
6259
6360
mkdir project-name && cd project-name
64-
python3 -m venv .venv
61+
python3 -m venv .env
6562
source .env/bin/activate
6663
pip3 install circuitpython-homie
6764
6865
Installing to a Connected CircuitPython Device with Circup
69-
==========================================================
66+
**********************************************************
7067

7168
Make sure that you have ``circup`` installed in your Python environment.
7269
Install it with the following command if necessary:
@@ -88,24 +85,32 @@ Or the following command to update an existing version:
8885
8986
circup update
9087
91-
Usage Example
92-
=============
88+
Usage Examples
89+
--------------
9390

94-
.. admonition:: todo
91+
Using the examples requires a secrets.py file that stores your secret information about the MQTT
92+
broker and network settings. This is `described with detail in the documentation
93+
<https://circuitpython-homie.rtfd.io/en/latest/examples.html>`_.
9594

96-
Add a quick, simple example. It and other examples should live in the
97-
examples folder and be included in docs/examples.rst.
95+
See the examples in the
96+
`examples <https://github.com/2bndy5/CircuitPython_Homie/tree/main/examples>`_ folder.
97+
These will be included with the Circuitpython Community bundle as well.
9898

9999
Documentation
100-
=============
101-
API documentation for this library can be found on `Read the Docs <https://circuitpython-homie.readthedocs.io/>`_.
100+
-------------
101+
102+
.. _Contributing Guidelines: https://circuitpython-homie.rtfd.io/en/latest/contributing.html
102103

103-
For information on building library documentation, please check out
104-
`this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.
104+
API documentation for this library can be found on
105+
`Read the Docs <https://circuitpython-homie.rtfd.io/>`_.
106+
107+
Instructions for build the documentation is in our `Contributing Guidelines`_.
105108

106109
Contributing
107-
============
110+
------------
108111

109112
Contributions are welcome! Please read our `Code of Conduct
110113
<https://github.com/2bndy5/CircuitPython_Homie/blob/HEAD/CODE_OF_CONDUCT.md>`_
111114
before contributing to help this project stay welcoming.
115+
116+
See also our `Contributing Guidelines`_ for information about the development workflow.

circuitpython_homie/__init__.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
#
33
# SPDX-License-Identifier: MIT
44
"""
5-
This module holds the Homie implementation for a device.
6-
See the nodes.py and properties.py for other Homie implementations.
5+
The :mod:`circuitpython_homie` module holds the Homie implementations for a
6+
:class:`device <HomieDevice>`, :class:`node <HomieNode>`, and
7+
:class:`property <HomieProperty>`. See the :mod:`circuitpython_homie.recipes` module
8+
for specialized properties that implement certain datatypes defined by the
9+
`Homie Specifications <https://homieiot.github.io/specification#payload>`_.
710
"""
811
try:
912
from os import uname # type: ignore
@@ -118,7 +121,7 @@ def __init__(
118121
datatype = datatype.lower()
119122
if datatype not in PAYLOAD_TYPES:
120123
raise ValueError("{} datatype is not in {}".format(datatype, PAYLOAD_TYPES))
121-
#: The property's :homie-attr:`datatype` attribute
124+
#: The property's :homie-attr:`datatype` attribute.
122125
self.datatype = datatype
123126
#: The property's value.
124127
self._value = init_value
@@ -207,16 +210,31 @@ def callback(self):
207210
Conventionally, this will require echoing the data back to the broker as
208211
confirmation.
209212
213+
.. seealso::
214+
Use `HomieDevice.set_property()` to echo back a confirmation to the MQTT
215+
broker.
210216
.. code-block:: python
211217
212-
my_prop = HomieProperty("signage", settable=True)
218+
prop1 = HomieProperty("signage", settable=True)
213219
214220
def new_signage(client: MQTT, topic, :str, message: str):
215-
print("received:", message)
216-
my_homie_device.set_property(my_prop, message)
217-
print("confirmation sent to broker")
221+
# let `my_device` be the instantiated HomieDevice object
222+
my_device.set_property(prop1, message) # confirm with broker
223+
# Optionally do something with the new value
224+
print("received:", prop1.value)
218225
219-
my_prop.callback = new_signage
226+
prop1.callback = new_signage
227+
.. details:: Using a lambda
228+
:class: info
229+
230+
CircuitPython also supports `lambda` objects.
231+
232+
.. code-block:: python
233+
234+
prop2 = HomieProperty("signage", settable=True)
235+
prop2.callback = lambda *args: my_device.set_property(prop2, args[2])
236+
237+
This assumes that the property's `value` will be used elsewhere.
220238
"""
221239
if not self.is_settable():
222240
return None

circuitpython_homie/recipes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
"""The ``recipes`` module holds any suggested recipes for easily implementing common
2-
node properties.
1+
"""The :mod:`circuitpython_homie.recipes` module holds any suggested recipes for easily
2+
implementing common node properties.
33
44
.. important::
55
Callback methods are not templated for these properties. Users are advised to

docs/API/topology.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
Topology
22
========
33

4+
.. automodule:: circuitpython_homie
5+
46
This library's data structures follows the
57
`Homie specification's topology <https://homieiot.github.io/specification/#topology>`_.
68
Because this implementation is written in pure python, the attributes of a Homie

docs/contributing.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.. include:: ../CONTRIBUTING.rst

docs/examples.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Examples
22
========
33

4+
Prerequisites
5+
-------------
6+
47
All of these examples require a separate user-defined module named ``secrets.py``.
58
In this secrets module should be 2 `dict`\ s:
69

@@ -25,6 +28,15 @@ In this secrets module should be 2 `dict`\ s:
2528
port=1883, # the broker's port
2629
)
2730
31+
Dependencies
32+
************
33+
34+
Some examples use other third-party libraries (which are available in Adafruit's CircuitPython
35+
Library bundle). These libraries are listed in the examples/requirements.txt file for easy install.
36+
37+
.. literalinclude:: ../examples/requirements.txt
38+
:caption: examples/requirements.txt
39+
2840
Simple test
2941
------------
3042

docs/index.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525

2626
tutorials/openhab
2727

28+
.. toctree::
29+
:hidden:
30+
31+
contributing
32+
2833
.. include:: ../README.rst
2934

3035
Indices and tables

0 commit comments

Comments
 (0)