Initial commit: Template
authorBenjamin Braatz <bb@bbraatz.eu>
Wed, 23 Aug 2023 03:17:40 +0000 (05:17 +0200)
committerBenjamin Braatz <bb@bbraatz.eu>
Wed, 23 Aug 2023 03:17:40 +0000 (05:17 +0200)
LICENSE [new file with mode: 0644]
README.md [new file with mode: 0644]
conf.json [new file with mode: 0644]
controlpi_plugins/example.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..042209c
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2023 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..a7026c1
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+# ControlPi Plugin for <PURPOSE>
+This distribution package contains a plugin for the
+[ControlPi system](https://docs.graph-it.com/graphit/controlpi), that
+<...>
+
+Documentation (in German) can be found at [doc/index.md](doc/index.md) in
+the source repository and at
+[https://docs.graph-it.com/graphit/controlpi-<NAME>/](https://docs.graph-it.com/graphit/controlpi-<NAME>/).
+Code documentation (in English) including doctests is contained in the
+source files.
diff --git a/conf.json b/conf.json
new file mode 100644 (file)
index 0000000..559c702
--- /dev/null
+++ b/conf.json
@@ -0,0 +1,16 @@
+{
+    "Debug": {
+        "plugin": "WSServer",
+        "web": {
+            "/": {
+                "module": "controlpi_plugins.wsserver",
+                "location": "Debug"
+            }
+        }
+    },
+    "Log": {
+        "plugin": "Log",
+        "filter": [{}]
+    },
+    <...>
+}
diff --git a/controlpi_plugins/example.py b/controlpi_plugins/example.py
new file mode 100644 (file)
index 0000000..72284c9
--- /dev/null
@@ -0,0 +1,41 @@
+"""ControlPi Plugin for <PURPOSE>."""
+import asyncio
+
+from controlpi import BasePlugin, Message, MessageTemplate
+from controlpi.baseplugin import JSONSchema
+
+
+class Example(BasePlugin):
+    """ControlPi plugin for <PURPOSE>."""
+
+    CONF_SCHEMA: JSONSchema = {'properties':
+                               {'init': {'type': 'boolean',
+                                         'default': False}},
+                               'required': []}
+
+    def process_conf(self) -> None:
+        """Register bus client."""
+        self._state = self.conf['init']
+        self.bus.register(self.name, 'Example',
+                          [MessageTemplate({'event':
+                                            {'const': 'changed'},
+                                            'state':
+                                            {'type': 'boolean'}}),
+                           MessageTemplate({'state':
+                                            {'type': 'boolean'}})],
+                          [([MessageTemplate({'target':
+                                              {'const': self.name},
+                                              'command':
+                                              {'const': 'get state'}})],
+                            self._get_state)])
+
+    async def _get_state(self, message) -> None:
+        await self.bus.send(Message(self.name, {'state': self._state}))
+
+    async def run(self) -> None:
+        """Run main loop of the plugin."""
+        while True:
+            self._state = not self._state
+            await self.bus.send(Message(self.name, {'event': 'changed',
+                                                    'state': self._state}))
+            await asyncio.sleep(10)
diff --git a/doc/index.md b/doc/index.md
new file mode 100644 (file)
index 0000000..4a1d3c2
--- /dev/null
@@ -0,0 +1,53 @@
+# ControlPi-Plugin für <ZWECK>
+Dieses Paket enthält ein Plugin für das ControlPi-System, mit dem <...>
+
+## 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-<NAME>.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-<NAME>.git
+```
+
+## Benutzung
+Eine minimale ControlPi-Konfiguration, die dieses Plugin benutzt, ist im
+git-Repository enthalten:
+```json
+{
+    "Debug": {
+        "plugin": "WSServer",
+        "web": {
+            "/": {
+                "module": "controlpi_plugins.wsserver",
+                "location": "Debug"
+            }
+        }
+    },
+    "Log": {
+        "plugin": "Log",
+        "filter": [{}]
+    },
+    <...>
+}
+```
+
+<...>
+
+Mit dieser Beispiel-Konfiguration kann <...>  in der Debug-Oberfläche des
+ControlPi und im Log in `journalctl -u controlpi` gesehen werden:
+![Debug-Oberfläche](graphit/controlpi-<NAME>/DebugView.png)
diff --git a/setup.py b/setup.py
new file mode 100644 (file)
index 0000000..13dd6d5
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,24 @@
+import setuptools
+
+with open("README.md", "r") as readme_file:
+    long_description = readme_file.read()
+
+setuptools.setup(
+    name="controlpi-<NAME>",
+    version="0.1.0",
+    author="Graph-IT GmbH",
+    author_email="info@graph-it.com",
+    description="ControlPi Plugin for <PURPOSE>",
+    long_description=long_description,
+    long_description_content_type="text/markdown",
+    url="http://docs.graph-it.com/graphit/controlpi-<NAME>",
+    packages=["controlpi_plugins"],
+    install_requires=[
+        "controlpi @ git+git://git.graph-it.com/graphit/controlpi.git",
+    ],
+    classifiers=[
+        "Programming Language :: Python",
+        "License :: OSI Approved :: MIT License",
+        "Operating System :: OS Independent",
+    ],
+)