Browse Source

Set up documentation using Sphinx

This is a good basis for documentation, which can be easily hosted anywhere.

Closes #4.
Stan Janssen 4 years ago
parent
commit
d6b108d72c
10 changed files with 372 additions and 0 deletions
  1. 1 0
      .gitignore
  2. 20 0
      docs/Makefile
  3. 13 0
      docs/client.rst
  4. 54 0
      docs/conf.py
  5. 58 0
      docs/examples.rst
  6. 130 0
      docs/index.rst
  7. 35 0
      docs/make.bat
  8. 35 0
      docs/openadr.rst
  9. 6 0
      docs/representations.rst
  10. 20 0
      docs/server.rst

+ 1 - 0
.gitignore

@@ -1,3 +1,4 @@
 python_env/
 __pycache__
 pyopenadr.egg-info
+docs/_build/

+ 20 - 0
docs/Makefile

@@ -0,0 +1,20 @@
+# Minimal makefile for Sphinx documentation
+#
+
+# You can set these variables from the command line, and also
+# from the environment for the first two.
+SPHINXOPTS    ?=
+SPHINXBUILD   ?= sphinx-build
+SOURCEDIR     = .
+BUILDDIR      = _build
+
+# Put it first so that "make" without argument is like "make help".
+help:
+	@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
+
+.PHONY: help Makefile
+
+# Catch-all target: route all unknown targets to Sphinx using the new
+# "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
+%: Makefile
+	@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

+ 13 - 0
docs/client.rst

@@ -0,0 +1,13 @@
+======
+Client
+======
+
+The page contains all information about aiohttp Client API.
+
+.. _client_events:
+Dealing with Events
+===================
+
+.. _client_reports:
+Dealing with Reports
+====================

+ 54 - 0
docs/conf.py

@@ -0,0 +1,54 @@
+# Configuration file for the Sphinx documentation builder.
+#
+# This file only contains a selection of the most common options. For a full
+# list see the documentation:
+# https://www.sphinx-doc.org/en/master/usage/configuration.html
+
+# -- Path setup --------------------------------------------------------------
+
+# If extensions (or modules to document with autodoc) are in another directory,
+# add these directories to sys.path here. If the directory is relative to the
+# documentation root, use os.path.abspath to make it absolute, like shown here.
+#
+# import os
+# import sys
+# sys.path.insert(0, os.path.abspath('.'))
+
+
+# -- Project information -----------------------------------------------------
+
+project = 'pyOpenADR'
+copyright = '2020, Stan Janssen'
+author = 'Stan Janssen'
+
+# The full version, including alpha/beta/rc tags
+release = '0.1.0'
+
+
+# -- 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']
+
+# Add any paths that contain templates here, relative to this directory.
+templates_path = ['_templates']
+
+# List of patterns, relative to source directory, that match files and
+# directories to ignore when looking for source files.
+# This pattern also affects html_static_path and html_extra_path.
+exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
+
+
+# -- Options for HTML output -------------------------------------------------
+
+# The theme to use for HTML and HTML Help pages.  See the documentation for
+# a list of builtin themes.
+#
+html_theme = 'alabaster'
+
+# 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']

+ 58 - 0
docs/examples.rst

@@ -0,0 +1,58 @@
+.. _examples:
+
+Examples
+========
+
+This page contains examples for pyOpenADR:
+
+.. _client_example:
+
+Client Example
+==============
+
+This example sets up a minimal OpenADR Client (Virtual End Node):
+
+.. code-block:: python3
+
+    from pyopenadr import OpenADRClient
+    import asyncio
+
+    async def main():
+        client = OpenADRClient(ven_name="Device001", vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
+        client.on_event = handle_event
+        client.on_report = handle_report
+        await client.run()
+
+    async def handle_event(event):
+        """
+        This coroutine will be called
+        whenever there is an event to be handled.
+        """
+        print("There is an event!")
+        print(event)
+        return 'optIn'
+
+    async def handle_report(report):
+        """
+        This coroutine will be called
+        whenever there is a report from the VTN.
+        """
+        print("There is a report!")
+        print(report)
+
+    loop = asyncio.get_event_loop()
+    loop.create_task(main())
+    loop.run_forever()
+
+
+
+
+.. _server_example:
+
+Server Example
+==============
+
+.. _server_with_gui_example:
+
+Server with GUI Example
+=======================

+ 130 - 0
docs/index.rst

@@ -0,0 +1,130 @@
+.. pyOpenAdr documentation master file, created by
+   sphinx-quickstart on Thu Jul  9 14:09:27 2020.
+   You can adapt this file completely to your liking, but it should at least
+   contain the root `toctree` directive.
+
+====================
+Welcome to pyOpenADR
+====================
+
+Dead-simple Python implementation of an OpenADR client and server.
+
+Key Features
+============
+
+- Fully compliant OpenADR 2.0b implementation for both servers (Virtual Top Node) and clients (Virtual End Node)
+- Fully asyncio: you set up the coroutines that can handle certain events, and they get called when needed.
+- All messages are represented as simple Python dictionaries. All XML parsing and generation is done for you.
+- You only have to deal with your own logic.
+
+Library Installation
+====================
+
+.. code-block:: bash
+
+   $ pip install pyopenadr
+
+pyOpenADR is compatible with Python 3.6+
+
+Getting Started
+===============
+
+Client example::
+
+    from pyopenadr import OpenADRClient
+    import asyncio
+
+    async def main():
+        client = OpenADRClient(ven_name="Device001",
+                               vtn_url="http://localhost:8080/OpenADR2/Simple/2.0b")
+        client.on_event = handle_event
+        client.on_report = handle_report
+        await client.run()
+
+    async def handle_event(event):
+        """
+        This coroutine will be called
+        when there is an event to be handled.
+        """
+        print("There is an event!")
+        print(event)
+        # Do something to determine whether to Opt In or Opt Out
+        return 'optIn'
+
+    async def handle_report(report):
+        """
+        This coroutine will be called
+        when there is a report from the VTN.
+        """
+        print("There is a report!")
+        print(report)
+
+    loop = asyncio.get_event_loop()
+    loop.create_task(main())
+    loop.run_forever()
+
+This will connect to an OpenADR server (indicated by the vtn_url parameter), handle registration, start polling for events and reports, and will call your coroutines whenever an event or report is created for you.
+
+We have more examples available over at the :ref:`examples` page.
+
+Source Code
+===========
+
+The source code for this project is hosted at GitHub.
+
+Table of Contents
+=================
+
+We have prepared some ready-to-run examples for you to get started with OpenADR:
+
+.. toctree::
+   :name: mastertoc
+   :maxdepth: 2
+
+   openadr
+   client
+   server
+   representations
+   examples
+
+
+Representations of OpenADR payloads
+===================================
+
+PyOpenADR uses Python dictionaries and vanilla Python types (like datetime and timedelta) to represent the OpenADR payloads. These pages serve as a reference to these representations.
+
+For example, this XML payload:
+
+.. code-block:: xml
+
+    <?xml version="1.0" encoding="utf-8"?>
+    <oadrPayload xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://openadr.org/oadr-2.0b/2012/07" xsi:schemaLocation="http://openadr.org/oadr-2.0b/2012/07 oadr_20b.xsd">
+      <oadrSignedObject>
+        <oadrResponse ei:schemaVersion="2.0b" xmlns:ei="http://docs.oasis-open.org/ns/energyinterop/201110">
+          <ei:eiResponse>
+            <ei:responseCode>200</ei:responseCode>
+            <ei:responseDescription>OK</ei:responseDescription>
+            <requestID xmlns="http://docs.oasis-open.org/ns/energyinterop/201110/payloads" />
+          </ei:eiResponse>
+          <ei:venID>o57b65be83</ei:venID>
+        </oadrResponse>
+      </oadrSignedObject>
+    </oadrPayload>
+
+is represented in pyOpenADR as:
+
+.. code-block:: python3
+
+    {'response': {'response_code': 200,
+                  'response_description': 'OK'},
+     'ven_id': 'o57b65be83'}
+
+Read more about the representations at :ref:`representations`
+
+
+Indices and tables
+==================
+
+* :ref:`genindex`
+* :ref:`modindex`
+* :ref:`search`

+ 35 - 0
docs/make.bat

@@ -0,0 +1,35 @@
+@ECHO OFF
+
+pushd %~dp0
+
+REM Command file for Sphinx documentation
+
+if "%SPHINXBUILD%" == "" (
+	set SPHINXBUILD=sphinx-build
+)
+set SOURCEDIR=.
+set BUILDDIR=_build
+
+if "%1" == "" goto help
+
+%SPHINXBUILD% >NUL 2>NUL
+if errorlevel 9009 (
+	echo.
+	echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
+	echo.installed, then set the SPHINXBUILD environment variable to point
+	echo.to the full path of the 'sphinx-build' executable. Alternatively you
+	echo.may add the Sphinx directory to PATH.
+	echo.
+	echo.If you don't have Sphinx installed, grab it from
+	echo.http://sphinx-doc.org/
+	exit /b 1
+)
+
+%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+goto end
+
+:help
+%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
+
+:end
+popd

+ 35 - 0
docs/openadr.rst

@@ -0,0 +1,35 @@
+==============
+OpenADR Basics
+==============
+
+If you are coming to this module and are not (yet) familiar with the workings of OpenADR, read this.
+
+High-level overview
+===================
+
+OpenADR is a protocol that allows a server (called a Virtual Top Node or VTNs) to communicate 'Events' to connected clients (Called Virtual End Nodes or VENs). These Events are usually energy-related instructions to temporarily increase or reduce the power consumption by one or more devices represented by the VEN. The VEN periodically (typically every 10 seconds or so) sends a Poll request to the VTN to check if there are new events for them.
+
+The VEN will then decide whether or not to comply with the request in the Event, and send an Opt In or Opt Out response to the VTN.
+
+In order to track what happens after, there is a Reports mechanism in place that allows the VEN and the VTN to agree on what data should be reported.
+
+
+.. _registration:
+Registration
+============
+
+Here is the registration page
+
+
+
+.. _openadr_events:
+Events
+======
+
+This is the registration
+
+.. _openadr_reports:
+Reports
+=======
+
+This is the reports

+ 6 - 0
docs/representations.rst

@@ -0,0 +1,6 @@
+.. _representations:
+
+=======================
+Payload Representations
+=======================
+

+ 20 - 0
docs/server.rst

@@ -0,0 +1,20 @@
+.. _server:
+
+======
+Server
+======
+
+The page contains all information about pyOpenADR Server API.
+
+
+.. _server_registration:
+Registration
+============
+
+.. _server_events:
+Events
+======
+
+.. _server_reports:
+Reports
+=======