Initial commit of plugin structure
authorBenjamin Braatz <bb@bbraatz.eu>
Tue, 2 Mar 2021 22:12:33 +0000 (23:12 +0100)
committerBenjamin Braatz <bb@bbraatz.eu>
Tue, 2 Mar 2021 22:12:33 +0000 (23:12 +0100)
LICENSE [new file with mode: 0644]
README.md [new file with mode: 0644]
conf.json [new file with mode: 0644]
controlpi/plugins/statemachine.py [new file with mode: 0644]
doc/index.md [new file with mode: 0644]
setup.py [new file with mode: 0644]

diff --git a/LICENSE b/LICENSE
new file mode 100644 (file)
index 0000000..ebb8ac1
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2021 Graph-IT GmbH
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644 (file)
index 0000000..a2c6778
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# Control-Pi-Plugin für Statemachines
+Dieses Paket enthält ein Plugin für das ControlPi-System, mit dem
+Statemachines konfiguriert werden können, die auf Nachrichten des zentralen
+Nachrichten-Busses des ControlPi-Systems reagieren und bei
+Zustands-Wechseln Kommandos/Nachrichten an andere Komponenten des Systems
+schicken.
+
+Die Dokumentation kann unter [doc/index.md](doc/index.md) bzw.
+[https://docs.graph-it.com/graphit/controlpi-plugin](https://docs.graph-it.com/graphit/controlpi-plugin)
+gefunden werden.
diff --git a/conf.json b/conf.json
new file mode 100644 (file)
index 0000000..9f345ff
--- /dev/null
+++ b/conf.json
@@ -0,0 +1,68 @@
+{
+    "State": {
+        "plugin": "State"
+    },
+    "WaitCheck": {
+        "plugin": "Wait",
+        "seconds": 1.0
+    },
+    "TriggerStateCheck": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitCheck", "event": "finished" },
+        "to": { "target": "State", "command": "get state" }
+    },
+    "TriggerWaitCheck": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitCheck", "event": "finished" },
+        "to": { "target": "WaitCheck", "command": "wait" }
+    },
+    "WaitOn": {
+        "plugin": "Wait",
+        "seconds": 1.5
+    },
+    "TriggerStateOnOff": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitOn", "event": "finished" },
+        "to": { "target": "State", "command": "set state", "state": false }
+    },
+    "TriggerWaitOnOff": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitOn", "event": "finished" },
+        "to": { "target": "WaitOff", "command": "wait" }
+    },
+    "WaitOff": {
+        "plugin": "Wait",
+        "seconds": 1.5
+    },
+    "TriggerStateOffOn": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitOff", "event": "finished" },
+        "to": { "target": "State", "command": "set state", "state": true }
+    },
+    "TriggerWaitOffOn": {
+        "plugin": "Alias",
+        "from": { "sender": "WaitOff", "event": "finished" },
+        "to": { "target": "WaitOn", "command": "wait" }
+    },
+    "Test Procedure": {
+        "plugin": "Init",
+        "messages": [
+            { "event": "started" },
+            { "target": "WaitOff", "command": "wait" },
+            { "target": "WaitCheck", "command": "wait" },
+            { "event": "stopped" }
+        ]
+    },
+    "Debug Logger": {
+        "plugin": "Log",
+        "filter": [
+            {}
+        ]
+    },
+    "State Change Logger": {
+        "plugin": "Log",
+        "filter": [
+            { "sender": "State", "changed": true }
+        ]
+    }
+}
diff --git a/controlpi/plugins/statemachine.py b/controlpi/plugins/statemachine.py
new file mode 100644 (file)
index 0000000..df35898
--- /dev/null
@@ -0,0 +1,19 @@
+"""Provide …
+
+TODO: documentation, doctests
+"""
+from controlpi import BasePlugin, Message, PluginConfiguration
+
+
+class Statemachine(BasePlugin):
+    async def _receive(self, message: Message) -> None:
+        send_message = {'sender': self._name}
+        await self._bus.send(send_message)
+
+    def _process_conf(self, conf: PluginConfiguration) -> None:
+        self._bus.register(self._name, sends, receives, self._receive)
+        super()._process_conf(conf)
+
+    async def run(self) -> None:
+        await super().run()
+        await self._bus.send({'sender': self._name})
diff --git a/doc/index.md b/doc/index.md
new file mode 100644 (file)
index 0000000..7793eda
--- /dev/null
@@ -0,0 +1,32 @@
+# Control-Pi-Plugin für Statemachines
+Dieses Paket enthält ein Plugin für das ControlPi-System, mit dem
+Statemachines konfiguriert werden können, die auf Nachrichten des zentralen
+Nachrichten-Busses des ControlPi-Systems reagieren und bei
+Zustands-Wechseln Kommandos/Nachrichten an andere Komponenten des Systems
+schicken.
+
+## Installation
+Eine ausführliche Dokumentation ist in der Dokumentation der 
+[ControlPi-Infrastruktur](https://docs.graph-it.com/graphit/controlpi) zu
+finden.
+
+Der Code dieses Plugins kann mit git geclonet werden:
+```sh
+$ git clone git://git.graph-it.com/graphit/controlpi-statemachine.git
+```
+(Falls Zugang zu diesem Server per SSH besteht und Änderungen gepusht
+werden sollen, sollte stattdessen die SSH-URL benutzt werden.)
+
+Dann kann es editierbar in ein virtuelles Environment installiert werden:
+```sh
+(venv)$ pip install --editable <Pfad zum Code-Repository>
+```
+
+Auf dem Raspberry Pi (oder wenn keine Code-Änderungen gewünscht sind) kann
+es auch direkt, ohne einen git-Clone installiert werden:
+```sh
+(venv)$ pip install git+git://git.graph-it.com/graphit/controlpi-statemachine.git
+```
+
+## Benutzung
+…
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..58a3bfc
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,21 @@
+import setuptools
+
+with open("README.md", "r") as readme_file:
+    long_description = readme_file.read()
+
+setuptools.setup(
+    name="controlpi-statemachine",
+    version="0.1.0",
+    author="Graph-IT GmbH",
+    author_email="info@graph-it.com",
+    description="Control-Pi-Plugin für Statemachines",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="http://docs.graph-it.com/graphit/controlpi-statemachine",
+    packages=['controlpi.plugins'],
+    classifiers=[
+        "Programming Language :: Python",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+    ],
+)