mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-21 22:48:16 +01:00
Standards & Guideliens
This commit is contained in:
parent
18a7d885a4
commit
fc65d3e33e
21 changed files with 702 additions and 824 deletions
File diff suppressed because it is too large
Load diff
|
@ -1,12 +1,10 @@
|
|||
import time
|
||||
|
||||
import asyncio
|
||||
|
||||
import logging
|
||||
from abc import abstractmethod
|
||||
from abc import abstractmethod,ABCMeta
|
||||
|
||||
|
||||
class SimpleStep(object):
|
||||
class CBPiSimpleStep(metaclass=ABCMeta):
|
||||
|
||||
__dirty = False
|
||||
managed_fields = []
|
||||
|
@ -17,7 +15,7 @@ class SimpleStep(object):
|
|||
def __init__(self, *args, **kwargs):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
for a in kwargs:
|
||||
super(SimpleStep, self).__setattr__(a, kwargs.get(a))
|
||||
super(CBPiSimpleStep, self).__setattr__(a, kwargs.get(a))
|
||||
self.id = kwargs.get("id")
|
||||
self.is_stopped = False
|
||||
self.is_next = False
|
||||
|
@ -52,7 +50,7 @@ class SimpleStep(object):
|
|||
try:
|
||||
await self.run_cycle()
|
||||
except Exception as e:
|
||||
logging.exception("SimpleStep Error")
|
||||
logging.exception("CBPiSimpleStep Error")
|
||||
self._exception_count = self._exception_count + 1
|
||||
if self._exception_count == self._max_exceptions:
|
||||
self.logger.error("Step Exception limit exceeded. Stopping Step")
|
||||
|
@ -126,6 +124,6 @@ class SimpleStep(object):
|
|||
def __setattr__(self, name, value):
|
||||
if name != "_Step__dirty" and name in self.managed_fields:
|
||||
self.__dirty = True
|
||||
super(SimpleStep, self).__setattr__(name, value)
|
||||
super(CBPiSimpleStep, self).__setattr__(name, value)
|
||||
else:
|
||||
super(SimpleStep, self).__setattr__(name, value)
|
||||
super(CBPiSimpleStep, self).__setattr__(name, value)
|
|
@ -1,4 +1,6 @@
|
|||
class CRUDController(object):
|
||||
from abc import abstractmethod,ABCMeta
|
||||
|
||||
class CRUDController(metaclass=ABCMeta):
|
||||
|
||||
|
||||
cache = {}
|
||||
|
|
|
@ -4,8 +4,6 @@ from core.api.decorator import on_event
|
|||
class NotificationController():
|
||||
'''
|
||||
This the notification controller
|
||||
|
||||
|
||||
'''
|
||||
|
||||
def __init__(self, cbpi):
|
||||
|
@ -17,8 +15,7 @@ class NotificationController():
|
|||
self.cbpi = cbpi
|
||||
self.cbpi.register(self)
|
||||
|
||||
@on_event(topic="notification/#")
|
||||
def on_event(self, key, message, type, **kwargs):
|
||||
|
||||
print("EVENT RECHEICVED", kwargs)
|
||||
@on_event(topic="notification/#")
|
||||
def _on_event(self, key, message, type, **kwargs):
|
||||
self.cbpi.ws.send("YES")
|
|
@ -13,7 +13,7 @@ from core.api.extension import CBPiExtension
|
|||
from core.api.kettle_logic import CBPiKettleLogic
|
||||
from core.api.property import Property
|
||||
from core.api.sensor import CBPiSensor
|
||||
from core.api.step import SimpleStep
|
||||
from core.api.step import CBPiSimpleStep
|
||||
from core.utils.utils import load_config, json_dumps
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
@ -31,7 +31,7 @@ class PluginController():
|
|||
@classmethod
|
||||
async def load_plugin_list(self):
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.get('https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins.yaml') as resp:
|
||||
async with session.get('https://raw.githubusercontent.com/Manuel83/craftbeerpi-plugins/master/plugins_v4.yaml') as resp:
|
||||
|
||||
if(resp.status == 200):
|
||||
|
||||
|
@ -101,7 +101,7 @@ class PluginController():
|
|||
if issubclass(clazz, CBPiKettleLogic):
|
||||
self.cbpi.kettle.types[name] = {"class": clazz, "config": self._parse_props(clazz)}
|
||||
|
||||
if issubclass(clazz, SimpleStep):
|
||||
if issubclass(clazz, CBPiSimpleStep):
|
||||
self.cbpi.step.types[name] = self._parse_props(clazz)
|
||||
print(self.cbpi.step.types)
|
||||
if issubclass(clazz, CBPiExtension):
|
||||
|
|
|
@ -204,7 +204,7 @@ class StepController(HttpAPI, CRUDController):
|
|||
open_step = False
|
||||
for key, step in self.cache.items():
|
||||
if step.state is None:
|
||||
step_type = self.types["CustomStep"]
|
||||
step_type = self.types["CustomStepCBPi"]
|
||||
print("----------")
|
||||
print(step_type)
|
||||
print("----------")
|
||||
|
|
|
@ -222,7 +222,7 @@ class CraftBeerPi():
|
|||
:param type: notification type (info,warning,danger,successs)
|
||||
:return:
|
||||
'''
|
||||
self.bus.fire(topic="notification/1", key=key, message=message, type=type)
|
||||
self.bus.fire(topic="notification/%s" % key, key=key, message=message, type=type)
|
||||
|
||||
|
||||
def setup(self):
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
import asyncio
|
||||
|
||||
from core.api import Property, action
|
||||
from core.api.step import SimpleStep
|
||||
from core.api.step import CBPiSimpleStep
|
||||
|
||||
|
||||
class CustomStep(SimpleStep):
|
||||
class CustomStepCBPi(CBPiSimpleStep):
|
||||
|
||||
name = Property.Number(label="Test")
|
||||
|
||||
|
@ -19,7 +19,7 @@ class CustomStep(SimpleStep):
|
|||
|
||||
#await asyncio.sleep(1)
|
||||
self.i = self.i + 1
|
||||
|
||||
self.cbpi.notify(key="step", message="OH YES")
|
||||
print("RUN STEP", self.id, self.name, self.__dict__)
|
||||
|
||||
|
||||
|
@ -32,4 +32,4 @@ def setup(cbpi):
|
|||
:return:
|
||||
'''
|
||||
|
||||
cbpi.plugin.register("CustomStep", CustomStep)
|
||||
cbpi.plugin.register("CustomStepCBPi", CustomStepCBPi)
|
||||
|
|
|
@ -17,6 +17,7 @@ Welcome to CraftBeerPi's documentation!
|
|||
step
|
||||
kettle_controller
|
||||
properties
|
||||
standards
|
||||
|
||||
|
||||
..
|
||||
|
|
56
docs/_sources/standards.rst.txt
Normal file
56
docs/_sources/standards.rst.txt
Normal file
|
@ -0,0 +1,56 @@
|
|||
Standard & Guidelines
|
||||
=====================
|
||||
|
||||
Python
|
||||
^^^^^^
|
||||
|
||||
CraftBeerPi 4.x is based on Pyhton 3.7x. as main frameworks is `aiohttp` used.
|
||||
|
||||
* aioHTTP https://aiohttp.readthedocs.io/en/stable/
|
||||
|
||||
EventBus
|
||||
--------
|
||||
|
||||
One core concept of CraftBeerPi 4.x is the EventBus.
|
||||
It should be avoided to call method on a controller directly. Events should be fired and listener methods should be used.
|
||||
This makes sure that all components are loosely coupled. New plugins can listen on events and extend or change the functionality easily.
|
||||
|
||||
Here an example how to fire an event
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
cbpi.bus.fire(topic="notification/hello", key="hello", message="Hello World")
|
||||
|
||||
|
||||
Here an example how listen on an event.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@on_event(topic="actor/+/switch/on")
|
||||
def listener(self, id , power=100, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
It's imporante to add **kwargs as parameter to the listening method. This makes sure that maybe addtional event paramenter are not causing an exception.
|
||||
|
||||
|
||||
Web User Interface
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
The Web UI is based on ReactJS + Redux.
|
||||
The build process is based on webpack and bable.
|
||||
|
||||
* ReactJS: https://reactjs.org/
|
||||
* Redux: https://redux.js.org/
|
||||
* WebPack: https://webpack.js.org/
|
||||
* Babel: https://babeljs.io
|
||||
|
||||
REST API
|
||||
^^^^^^^^
|
||||
The REST API of CraftBeerPi is documented using Swagger.io
|
||||
After server startup you can find the API documentaiton under: `http://<IP_ADDRESS>:<PORT>/api/doc`
|
||||
|
||||
To generate the swagger file `aiohttp-swagger` is used. for more information see: https://aiohttp-swagger.readthedocs.io/en/latest/
|
||||
|
||||
|
|
@ -13,17 +13,17 @@ StepController
|
|||
:show-inheritance:
|
||||
|
||||
|
||||
SimpleStep
|
||||
^^^^^^^^^^
|
||||
CBPiSimpleStep
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: core.api.step.SimpleStep
|
||||
.. autoclass:: core.api.step.CBPiSimpleStep
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Custom Step
|
||||
^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^
|
||||
|
||||
This is an example of a custom step. The Step class need to extend Simple step. In addtion at least the run_cycle method needs to be overwritten
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
<li class="toctree-l1"><a class="reference internal" href="step.html">Brewing Step</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="kettle_controller.html">Kettle</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="properties.html">Properties</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="standards.html">Standard & Guidelines</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -195,11 +196,13 @@
|
|||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="actor.html#core.api.actor.CBPiActor">CBPiActor (class in core.api.actor)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="kettle_controller.html#core.api.kettle_logic.CBPiKettleLogic">CBPiKettleLogic (class in core.api.kettle_logic)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="sensor.html#core.api.sensor.CBPiSensor">CBPiSensor (class in core.api.sensor)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep">CBPiSimpleStep (class in core.api.step)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -269,7 +272,7 @@
|
|||
</ul></li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.is_dirty">is_dirty() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.is_dirty">is_dirty() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -293,7 +296,7 @@
|
|||
<h2 id="M">M</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.managed_fields">managed_fields (core.api.step.SimpleStep attribute)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.managed_fields">managed_fields (core.api.step.CBPiSimpleStep attribute)</a>
|
||||
</li>
|
||||
<li><a href="actor.html#core.controller.actor_controller.ActorController.model">model (core.controller.actor_controller.ActorController attribute)</a>
|
||||
|
||||
|
@ -309,7 +312,7 @@
|
|||
<h2 id="N">N</h2>
|
||||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.next">next() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.next">next() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -361,23 +364,23 @@
|
|||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="actor.html#core.controller.actor_controller.ActorController.register">register() (core.controller.actor_controller.ActorController method)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.reset">reset() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.reset">reset() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.reset_dirty">reset_dirty() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.reset_dirty">reset_dirty() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
<li><a href="kettle_controller.html#core.api.kettle_logic.CBPiKettleLogic.run">run() (core.api.kettle_logic.CBPiKettleLogic method)</a>
|
||||
|
||||
<ul>
|
||||
<li><a href="sensor.html#core.api.sensor.CBPiSensor.run">(core.api.sensor.CBPiSensor method)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.run">(core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.run">(core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.run_cycle">run_cycle() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.run_cycle">run_cycle() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.running">running() (core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.running">running() (core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
</ul></td>
|
||||
</tr></table>
|
||||
|
@ -386,8 +389,6 @@
|
|||
<table style="width: 100%" class="indextable genindextable"><tr>
|
||||
<td style="width: 33%; vertical-align: top;"><ul>
|
||||
<li><a href="sensor.html#core.controller.sensor_controller.SensorController">SensorController (class in core.controller.sensor_controller)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.api.step.SimpleStep">SimpleStep (class in core.api.step)</a>
|
||||
</li>
|
||||
<li><a href="step.html#core.controller.step_controller.StepController.start">start() (core.controller.step_controller.StepController method)</a>
|
||||
</li>
|
||||
|
@ -404,7 +405,7 @@
|
|||
<li><a href="kettle_controller.html#core.api.kettle_logic.CBPiKettleLogic.stop">stop() (core.api.kettle_logic.CBPiKettleLogic method)</a>
|
||||
|
||||
<ul>
|
||||
<li><a href="step.html#core.api.step.SimpleStep.stop">(core.api.step.SimpleStep method)</a>
|
||||
<li><a href="step.html#core.api.step.CBPiSimpleStep.stop">(core.api.step.CBPiSimpleStep method)</a>
|
||||
</li>
|
||||
</ul></li>
|
||||
</ul></td>
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
<li class="toctree-l1"><a class="reference internal" href="step.html">Brewing Step</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="kettle_controller.html">Kettle</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="properties.html">Properties</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="standards.html">Standard & Guidelines</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
@ -170,7 +171,7 @@
|
|||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="step.html">Brewing Step</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="step.html#stepcontroller">StepController</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="step.html#simplestep">SimpleStep</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="step.html#cbpisimplestep">CBPiSimpleStep</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="step.html#custom-step">Custom Step</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -184,6 +185,15 @@
|
|||
<li class="toctree-l2"><a class="reference internal" href="properties.html#custom-actor">Custom Actor</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="standards.html">Standard & Guidelines</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="standards.html#python">Python</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="standards.html#eventbus">EventBus</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="standards.html#web-user-interface">Web User Interface</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="standards.html#rest-api">REST API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
|
BIN
docs/objects.inv
BIN
docs/objects.inv
Binary file not shown.
|
@ -84,6 +84,7 @@
|
|||
<li class="toctree-l1"><a class="reference internal" href="step.html">Brewing Step</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="kettle_controller.html">Kettle</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="properties.html">Properties</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="standards.html">Standard & Guidelines</a></li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
265
docs/standards.html
Normal file
265
docs/standards.html
Normal file
|
@ -0,0 +1,265 @@
|
|||
|
||||
|
||||
<!DOCTYPE html>
|
||||
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
|
||||
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
||||
<title>Standard & Guidelines — CraftBeerPi 4.0 documentation</title>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
|
||||
<link rel="stylesheet" href="_static/pygments.css" type="text/css" />
|
||||
<link rel="index" title="Index" href="genindex.html" />
|
||||
<link rel="search" title="Search" href="search.html" />
|
||||
<link rel="prev" title="Properties" href="properties.html" />
|
||||
|
||||
|
||||
<script src="_static/js/modernizr.min.js"></script>
|
||||
|
||||
</head>
|
||||
|
||||
<body class="wy-body-for-nav">
|
||||
|
||||
|
||||
<div class="wy-grid-for-nav">
|
||||
|
||||
|
||||
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
|
||||
<div class="wy-side-scroll">
|
||||
<div class="wy-side-nav-search">
|
||||
|
||||
|
||||
|
||||
<a href="index.html" class="icon icon-home"> CraftBeerPi
|
||||
|
||||
|
||||
|
||||
</a>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div role="search">
|
||||
<form id="rtd-search-form" class="wy-form" action="search.html" method="get">
|
||||
<input type="text" name="q" placeholder="Search docs" />
|
||||
<input type="hidden" name="check_keywords" value="yes" />
|
||||
<input type="hidden" name="area" value="default" />
|
||||
</form>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<ul class="current">
|
||||
<li class="toctree-l1"><a class="reference internal" href="install.html">Installation</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="core.html">Core</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="actor.html">Actor</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="sensor.html">Sensor</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="step.html">Brewing Step</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="kettle_controller.html">Kettle</a></li>
|
||||
<li class="toctree-l1"><a class="reference internal" href="properties.html">Properties</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Standard & Guidelines</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#python">Python</a><ul>
|
||||
<li class="toctree-l3"><a class="reference internal" href="#eventbus">EventBus</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#web-user-interface">Web User Interface</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#rest-api">REST API</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
|
||||
|
||||
|
||||
<nav class="wy-nav-top" aria-label="top navigation">
|
||||
|
||||
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
|
||||
<a href="index.html">CraftBeerPi</a>
|
||||
|
||||
</nav>
|
||||
|
||||
|
||||
<div class="wy-nav-content">
|
||||
|
||||
<div class="rst-content">
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<div role="navigation" aria-label="breadcrumbs navigation">
|
||||
|
||||
<ul class="wy-breadcrumbs">
|
||||
|
||||
<li><a href="index.html">Docs</a> »</li>
|
||||
|
||||
<li>Standard & Guidelines</li>
|
||||
|
||||
|
||||
<li class="wy-breadcrumbs-aside">
|
||||
|
||||
|
||||
<a href="_sources/standards.rst.txt" rel="nofollow"> View page source</a>
|
||||
|
||||
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
|
||||
<hr/>
|
||||
</div>
|
||||
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
|
||||
<div itemprop="articleBody">
|
||||
|
||||
<div class="section" id="standard-guidelines">
|
||||
<h1>Standard & Guidelines<a class="headerlink" href="#standard-guidelines" title="Permalink to this headline">¶</a></h1>
|
||||
<div class="section" id="python">
|
||||
<h2>Python<a class="headerlink" href="#python" title="Permalink to this headline">¶</a></h2>
|
||||
<p>CraftBeerPi 4.x is based on Pyhton 3.7x. as main frameworks is <cite>aiohttp</cite> used.</p>
|
||||
<ul class="simple">
|
||||
<li>aioHTTP <a class="reference external" href="https://aiohttp.readthedocs.io/en/stable/">https://aiohttp.readthedocs.io/en/stable/</a></li>
|
||||
</ul>
|
||||
<div class="section" id="eventbus">
|
||||
<h3>EventBus<a class="headerlink" href="#eventbus" title="Permalink to this headline">¶</a></h3>
|
||||
<p>One core concept of CraftBeerPi 4.x is the EventBus.
|
||||
It should be avoided to call method on a controller directly. Events should be fired and listener methods should be used.
|
||||
This makes sure that all components are loosely coupled. New plugins can listen on events and extend or change the functionality easily.</p>
|
||||
<p>Here an example how to fire an event</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="n">cbpi</span><span class="o">.</span><span class="n">bus</span><span class="o">.</span><span class="n">fire</span><span class="p">(</span><span class="n">topic</span><span class="o">=</span><span class="s2">"notification/hello"</span><span class="p">,</span> <span class="n">key</span><span class="o">=</span><span class="s2">"hello"</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">"Hello World"</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<p>Here an example how listen on an event.</p>
|
||||
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="nd">@on_event</span><span class="p">(</span><span class="n">topic</span><span class="o">=</span><span class="s2">"actor/+/switch/on"</span><span class="p">)</span>
|
||||
<span class="k">def</span> <span class="nf">listener</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="nb">id</span> <span class="p">,</span> <span class="n">power</span><span class="o">=</span><span class="mi">100</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span> <span class="o">-></span> <span class="bp">None</span><span class="p">:</span>
|
||||
<span class="k">pass</span>
|
||||
</pre></div>
|
||||
</div>
|
||||
<div class="admonition note">
|
||||
<p class="first admonition-title">Note</p>
|
||||
<p class="last">It’s imporante to add <a href="#id1"><span class="problematic" id="id2">**</span></a>kwargs as parameter to the listening method. This makes sure that maybe addtional event paramenter are not causing an exception.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="section" id="web-user-interface">
|
||||
<h2>Web User Interface<a class="headerlink" href="#web-user-interface" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The Web UI is based on ReactJS + Redux.
|
||||
The build process is based on webpack and bable.</p>
|
||||
<ul class="simple">
|
||||
<li>ReactJS: <a class="reference external" href="https://reactjs.org/">https://reactjs.org/</a></li>
|
||||
<li>Redux: <a class="reference external" href="https://redux.js.org/">https://redux.js.org/</a></li>
|
||||
<li>WebPack: <a class="reference external" href="https://webpack.js.org/">https://webpack.js.org/</a></li>
|
||||
<li>Babel: <a class="reference external" href="https://babeljs.io">https://babeljs.io</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="section" id="rest-api">
|
||||
<h2>REST API<a class="headerlink" href="#rest-api" title="Permalink to this headline">¶</a></h2>
|
||||
<p>The REST API of CraftBeerPi is documented using Swagger.io
|
||||
After server startup you can find the API documentaiton under: <cite>http://<IP_ADDRESS>:<PORT>/api/doc</cite></p>
|
||||
<p>To generate the swagger file <cite>aiohttp-swagger</cite> is used. for more information see: <a class="reference external" href="https://aiohttp-swagger.readthedocs.io/en/latest/">https://aiohttp-swagger.readthedocs.io/en/latest/</a></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<footer>
|
||||
|
||||
<div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
|
||||
|
||||
|
||||
<a href="properties.html" class="btn btn-neutral" title="Properties" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<hr/>
|
||||
|
||||
<div role="contentinfo">
|
||||
<p>
|
||||
© Copyright 2018, Manuel Fritsch
|
||||
|
||||
</p>
|
||||
</div>
|
||||
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
|
||||
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</section>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
|
||||
<script type="text/javascript" src="_static/jquery.js"></script>
|
||||
<script type="text/javascript" src="_static/underscore.js"></script>
|
||||
<script type="text/javascript" src="_static/doctools.js"></script>
|
||||
|
||||
|
||||
|
||||
|
||||
<script type="text/javascript" src="_static/js/theme.js"></script>
|
||||
|
||||
<script type="text/javascript">
|
||||
jQuery(function () {
|
||||
SphinxRtdTheme.Navigation.enable(true);
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -85,7 +85,7 @@
|
|||
<li class="toctree-l1"><a class="reference internal" href="sensor.html">Sensor</a></li>
|
||||
<li class="toctree-l1 current"><a class="current reference internal" href="#">Brewing Step</a><ul>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#stepcontroller">StepController</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#simplestep">SimpleStep</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#cbpisimplestep">CBPiSimpleStep</a></li>
|
||||
<li class="toctree-l2"><a class="reference internal" href="#custom-step">Custom Step</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
|
@ -367,15 +367,15 @@ Stops the current step</p>
|
|||
</dd></dl>
|
||||
|
||||
</div>
|
||||
<div class="section" id="simplestep">
|
||||
<h2>SimpleStep<a class="headerlink" href="#simplestep" title="Permalink to this headline">¶</a></h2>
|
||||
<div class="section" id="cbpisimplestep">
|
||||
<h2>CBPiSimpleStep<a class="headerlink" href="#cbpisimplestep" title="Permalink to this headline">¶</a></h2>
|
||||
<dl class="class">
|
||||
<dt id="core.api.step.SimpleStep">
|
||||
<em class="property">class </em><code class="descclassname">core.api.step.</code><code class="descname">SimpleStep</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep">
|
||||
<em class="property">class </em><code class="descclassname">core.api.step.</code><code class="descname">CBPiSimpleStep</code><span class="sig-paren">(</span><em>*args</em>, <em>**kwargs</em><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></p>
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.is_dirty">
|
||||
<code class="descname">is_dirty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.is_dirty" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.is_dirty">
|
||||
<code class="descname">is_dirty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.is_dirty" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Check if a managed variable has a new value</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
|
@ -388,13 +388,13 @@ Stops the current step</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="attribute">
|
||||
<dt id="core.api.step.SimpleStep.managed_fields">
|
||||
<code class="descname">managed_fields</code><em class="property"> = []</em><a class="headerlink" href="#core.api.step.SimpleStep.managed_fields" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.managed_fields">
|
||||
<code class="descname">managed_fields</code><em class="property"> = []</em><a class="headerlink" href="#core.api.step.CBPiSimpleStep.managed_fields" title="Permalink to this definition">¶</a></dt>
|
||||
<dd></dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.next">
|
||||
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.next" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.next">
|
||||
<code class="descname">next</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.next" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Request to stop the the step</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
|
@ -407,8 +407,8 @@ Stops the current step</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.reset">
|
||||
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.reset" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.reset">
|
||||
<code class="descname">reset</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.reset" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Reset the step. This method needs to be overwritten by the custom step implementation</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
|
@ -421,8 +421,8 @@ Stops the current step</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.reset_dirty">
|
||||
<code class="descname">reset_dirty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.reset_dirty" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.reset_dirty">
|
||||
<code class="descname">reset_dirty</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.reset_dirty" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Reset the dirty flag</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
|
@ -435,8 +435,8 @@ Stops the current step</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.run">
|
||||
<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.run" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.run">
|
||||
<code class="descname">run</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.run" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>This method in running in the background. It invokes the run_cycle method in the configured interval
|
||||
It checks if a managed variable was modified in the last exection cycle. If yes, the method will persisit the new value of the
|
||||
managed property</p>
|
||||
|
@ -451,8 +451,8 @@ managed property</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.run_cycle">
|
||||
<code class="descname">run_cycle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.run_cycle" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.run_cycle">
|
||||
<code class="descname">run_cycle</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.run_cycle" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>This method is executed in the defined interval.
|
||||
That the place to put your step logic.
|
||||
The method need to be overwritten in the Ccstom step implementaion</p>
|
||||
|
@ -467,8 +467,8 @@ The method need to be overwritten in the Ccstom step implementaion</p>
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.running">
|
||||
<code class="descname">running</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.running" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.running">
|
||||
<code class="descname">running</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.running" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Method checks if the step should continue running.
|
||||
The method will return False if the step is requested to stop or the next step should start</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
|
@ -482,8 +482,8 @@ The method will return False if the step is requested to stop or the next step s
|
|||
</dd></dl>
|
||||
|
||||
<dl class="method">
|
||||
<dt id="core.api.step.SimpleStep.stop">
|
||||
<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.SimpleStep.stop" title="Permalink to this definition">¶</a></dt>
|
||||
<dt id="core.api.step.CBPiSimpleStep.stop">
|
||||
<code class="descname">stop</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#core.api.step.CBPiSimpleStep.stop" title="Permalink to this definition">¶</a></dt>
|
||||
<dd><p>Request to stop the step</p>
|
||||
<table class="docutils field-list" frame="void" rules="none">
|
||||
<col class="field-name" />
|
||||
|
@ -540,10 +540,10 @@ The method will return False if the step is requested to stop or the next step s
|
|||
35</pre></div></td><td class="code"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">asyncio</span>
|
||||
|
||||
<span class="kn">from</span> <span class="nn">core.api</span> <span class="kn">import</span> <span class="n">Property</span><span class="p">,</span> <span class="n">action</span>
|
||||
<span class="kn">from</span> <span class="nn">core.api.step</span> <span class="kn">import</span> <span class="n">SimpleStep</span>
|
||||
<span class="kn">from</span> <span class="nn">core.api.step</span> <span class="kn">import</span> <span class="n">CBPiSimpleStep</span>
|
||||
|
||||
|
||||
<span class="k">class</span> <span class="nc">CustomStep</span><span class="p">(</span><span class="n">SimpleStep</span><span class="p">):</span>
|
||||
<span class="k">class</span> <span class="nc">CustomStepCBPi</span><span class="p">(</span><span class="n">CBPiSimpleStep</span><span class="p">):</span>
|
||||
|
||||
<span class="n">name</span> <span class="o">=</span> <span class="n">Property</span><span class="o">.</span><span class="n">Number</span><span class="p">(</span><span class="n">label</span><span class="o">=</span><span class="s2">"Test"</span><span class="p">)</span>
|
||||
|
||||
|
@ -558,7 +558,7 @@ The method will return False if the step is requested to stop or the next step s
|
|||
|
||||
<span class="c1">#await asyncio.sleep(1)</span>
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">i</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">i</span> <span class="o">+</span> <span class="mi">1</span>
|
||||
|
||||
<span class="bp">self</span><span class="o">.</span><span class="n">cbpi</span><span class="o">.</span><span class="n">notify</span><span class="p">(</span><span class="n">key</span><span class="o">=</span><span class="s2">"step"</span><span class="p">,</span> <span class="n">message</span><span class="o">=</span><span class="s2">"OH YES"</span><span class="p">)</span>
|
||||
<span class="k">print</span><span class="p">(</span><span class="s2">"RUN STEP"</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">id</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="vm">__dict__</span><span class="p">)</span>
|
||||
|
||||
|
||||
|
@ -571,7 +571,7 @@ The method will return False if the step is requested to stop or the next step s
|
|||
<span class="sd"> :return: </span>
|
||||
<span class="sd"> '''</span>
|
||||
|
||||
<span class="n">cbpi</span><span class="o">.</span><span class="n">plugin</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="s2">"CustomStep"</span><span class="p">,</span> <span class="n">CustomStep</span><span class="p">)</span>
|
||||
<span class="n">cbpi</span><span class="o">.</span><span class="n">plugin</span><span class="o">.</span><span class="n">register</span><span class="p">(</span><span class="s2">"CustomStepCBPi"</span><span class="p">,</span> <span class="n">CustomStepCBPi</span><span class="p">)</span>
|
||||
</pre></div>
|
||||
</td></tr></table></div>
|
||||
</div>
|
||||
|
|
|
@ -17,6 +17,7 @@ Welcome to CraftBeerPi's documentation!
|
|||
step
|
||||
kettle_controller
|
||||
properties
|
||||
standards
|
||||
|
||||
|
||||
..
|
||||
|
|
56
docs_src/source/standards.rst
Normal file
56
docs_src/source/standards.rst
Normal file
|
@ -0,0 +1,56 @@
|
|||
Standard & Guidelines
|
||||
=====================
|
||||
|
||||
Python
|
||||
^^^^^^
|
||||
|
||||
CraftBeerPi 4.x is based on Pyhton 3.7x. as main frameworks is `aiohttp` used.
|
||||
|
||||
* aioHTTP https://aiohttp.readthedocs.io/en/stable/
|
||||
|
||||
EventBus
|
||||
--------
|
||||
|
||||
One core concept of CraftBeerPi 4.x is the EventBus.
|
||||
It should be avoided to call method on a controller directly. Events should be fired and listener methods should be used.
|
||||
This makes sure that all components are loosely coupled. New plugins can listen on events and extend or change the functionality easily.
|
||||
|
||||
Here an example how to fire an event
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
cbpi.bus.fire(topic="notification/hello", key="hello", message="Hello World")
|
||||
|
||||
|
||||
Here an example how listen on an event.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
@on_event(topic="actor/+/switch/on")
|
||||
def listener(self, id , power=100, **kwargs) -> None:
|
||||
pass
|
||||
|
||||
|
||||
.. note::
|
||||
|
||||
It's imporante to add **kwargs as parameter to the listening method. This makes sure that maybe addtional event paramenter are not causing an exception.
|
||||
|
||||
|
||||
Web User Interface
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
The Web UI is based on ReactJS + Redux.
|
||||
The build process is based on webpack and bable.
|
||||
|
||||
* ReactJS: https://reactjs.org/
|
||||
* Redux: https://redux.js.org/
|
||||
* WebPack: https://webpack.js.org/
|
||||
* Babel: https://babeljs.io
|
||||
|
||||
REST API
|
||||
^^^^^^^^
|
||||
The REST API of CraftBeerPi is documented using Swagger.io
|
||||
After server startup you can find the API documentaiton under: `http://<IP_ADDRESS>:<PORT>/api/doc`
|
||||
|
||||
To generate the swagger file `aiohttp-swagger` is used. for more information see: https://aiohttp-swagger.readthedocs.io/en/latest/
|
||||
|
||||
|
|
@ -13,17 +13,17 @@ StepController
|
|||
:show-inheritance:
|
||||
|
||||
|
||||
SimpleStep
|
||||
^^^^^^^^^^
|
||||
CBPiSimpleStep
|
||||
^^^^^^^^^^^^^^
|
||||
|
||||
.. autoclass:: core.api.step.SimpleStep
|
||||
.. autoclass:: core.api.step.CBPiSimpleStep
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
Custom Step
|
||||
^^^^^^^^^^^^^
|
||||
^^^^^^^^^^^
|
||||
|
||||
This is an example of a custom step. The Step class need to extend Simple step. In addtion at least the run_cycle method needs to be overwritten
|
||||
|
||||
|
|
Loading…
Reference in a new issue