From: Benjamin Braatz Date: Wed, 23 Aug 2023 04:32:13 +0000 (+0200) Subject: setup.py and plugin rename. X-Git-Url: http://git.graph-it.com/?a=commitdiff_plain;h=eb5b2c799fc3ed117be71eb4c3b455536674209b;p=graphit%2Fcontrolpi-readjson.git setup.py and plugin rename. --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ece8bc --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/venv/ +/controlpi_readjson.egg-info/ diff --git a/README.md b/README.md index a7026c1..c112267 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,12 @@ -# ControlPi Plugin for +# ControlPi Plugin for Reading JSON from a Serial Device This distribution package contains a plugin for the [ControlPi system](https://docs.graph-it.com/graphit/controlpi), that -<...> +opens a serial device, reads lines from it, and just sends them to the +ControlPi message bus if they can be interpreted as (arbitrary) JSON +objects/messages. 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-/](https://docs.graph-it.com/graphit/controlpi-/). +[https://docs.graph-it.com/graphit/controlpi-readjson/](https://docs.graph-it.com/graphit/controlpi-readjson/). Code documentation (in English) including doctests is contained in the source files. diff --git a/controlpi_plugins/example.py b/controlpi_plugins/example.py deleted file mode 100644 index 72284c9..0000000 --- a/controlpi_plugins/example.py +++ /dev/null @@ -1,41 +0,0 @@ -"""ControlPi Plugin for .""" -import asyncio - -from controlpi import BasePlugin, Message, MessageTemplate -from controlpi.baseplugin import JSONSchema - - -class Example(BasePlugin): - """ControlPi plugin for .""" - - 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/controlpi_plugins/readjson.py b/controlpi_plugins/readjson.py new file mode 100644 index 0000000..72284c9 --- /dev/null +++ b/controlpi_plugins/readjson.py @@ -0,0 +1,41 @@ +"""ControlPi Plugin for .""" +import asyncio + +from controlpi import BasePlugin, Message, MessageTemplate +from controlpi.baseplugin import JSONSchema + + +class Example(BasePlugin): + """ControlPi plugin for .""" + + 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/setup.py b/setup.py index 13dd6d5..51e3f5d 100644 --- a/setup.py +++ b/setup.py @@ -4,16 +4,17 @@ with open("README.md", "r") as readme_file: long_description = readme_file.read() setuptools.setup( - name="controlpi-", + name="controlpi-readjson", version="0.1.0", author="Graph-IT GmbH", author_email="info@graph-it.com", - description="ControlPi Plugin for ", + description="ControlPi Plugin for Reading JSON from a Serial Device", long_description=long_description, long_description_content_type="text/markdown", - url="http://docs.graph-it.com/graphit/controlpi-", + url="http://docs.graph-it.com/graphit/controlpi-readjson", packages=["controlpi_plugins"], install_requires=[ + "pyserial-asyncio", "controlpi @ git+git://git.graph-it.com/graphit/controlpi.git", ], classifiers=[