--- /dev/null
+"""Provide utility plugins for all kinds of systems.
+
+TODO: documentation, doctests, check configurations during _process_conf
+TODO: State, AndState, OrState?
+"""
+import asyncio
+
+from controlpi import BasePlugin, Message, PluginConfiguration
+
+
+class Log(BasePlugin):
+ async def _log(self, message: Message) -> None:
+ print(f"{self._name}: {message}")
+
+ def _process_conf(self, conf: PluginConfiguration) -> None:
+ self._bus.register(self._name, [], conf['filter'], self._log)
+ super()._process_conf(conf)
+
+
+class Init(BasePlugin):
+ async def _execute(self, message: Message) -> None:
+ for message in self._messages:
+ await self._bus.send(message)
+
+ def _process_conf(self, conf: PluginConfiguration) -> None:
+ self._messages = []
+ for message in conf['messages']:
+ complete_message = {'sender': self._name}
+ complete_message.update(message)
+ self._messages.append(complete_message)
+ receives = [{'target': self._name, 'command': 'execute'}]
+ sends = []
+ sends.extend(receives)
+ sends.extend(conf['messages'])
+ self._bus.register(self._name, sends, receives, self._execute)
+ super()._process_conf(conf)
+
+ async def run(self) -> None:
+ await super().run()
+ await self._bus.send({'sender': self._name, 'target': self._name,
+ 'command': 'execute'})
+
+
+class Wait(BasePlugin):
+ async def _wait(self, message: Message) -> None:
+ await asyncio.sleep(self._seconds)
+ await self._bus.send({'sender': self._name, 'event': 'finished'})
+
+ def _process_conf(self, conf: PluginConfiguration) -> None:
+ self._seconds = conf['seconds']
+ receives = [{'target': self._name, 'command': 'wait'}]
+ sends = [{'event': 'finished'}]
+ self._bus.register(self._name, sends, receives, self._wait)
+ super()._process_conf(conf)
+
+
+class Alias(BasePlugin):
+ async def _alias(self, message: Message) -> None:
+ alias_message = {}
+ alias_message['sender'] = self._name
+ alias_message.update(self._to)
+ for key in message:
+ if key != 'sender' and key not in self._from:
+ alias_message[key] = message[key]
+ await self._bus.send(alias_message)
+
+ def _process_conf(self, conf: PluginConfiguration) -> None:
+ self._from = conf['from']
+ self._to = conf['to']
+ self._bus.register(self._name, [self._to], [self._from], self._alias)
+ super()._process_conf(conf)
+
+
+class State(BasePlugin):
+ async def _receive(self, message: Message) -> None:
+ if 'command' in message:
+ if message['command'] == 'get state':
+ await self._bus.send({'sender': self._name,
+ 'state': self._state,
+ 'changed': False})
+ elif message['command'] == 'set state':
+ if 'state' in message and self._state != message['state']:
+ self._state: bool = message['state']
+ await self._bus.send({'sender': self._name,
+ 'state': self._state,
+ 'changed': True})
+
+ def _process_conf(self, conf: PluginConfiguration) -> None:
+ self._state = False
+ sends: list[Message] = [{'sender': self._name, 'state': bool}]
+ receives: list[Message] = [{'target': self._name,
+ 'command': 'get state'},
+ {'target': self._name,
+ 'command': 'set state',
+ 'state': bool}]
+ self._bus.register(self._name, sends, receives, self._receive)
+ super()._process_conf(conf)
"""
if not conf or not check_configuration(conf):
return
- plugins = PluginRegistry('controlpi.plugins', BasePlugin)
+ plugins = PluginRegistry('controlpi-plugins', BasePlugin)
message_bus = MessageBus()
coroutines = [message_bus.run()]
for instance_name in conf:
+++ /dev/null
-"""Provide utility plugins for all kinds of systems.
-
-TODO: documentation, doctests, check configurations during _process_conf
-TODO: State, AndState, OrState?
-"""
-import asyncio
-
-from controlpi import BasePlugin, Message, PluginConfiguration
-
-
-class Log(BasePlugin):
- async def _log(self, message: Message) -> None:
- print(f"{self._name}: {message}")
-
- def _process_conf(self, conf: PluginConfiguration) -> None:
- self._bus.register(self._name, [], conf['filter'], self._log)
- super()._process_conf(conf)
-
-
-class Init(BasePlugin):
- async def _execute(self, message: Message) -> None:
- for message in self._messages:
- await self._bus.send(message)
-
- def _process_conf(self, conf: PluginConfiguration) -> None:
- self._messages = []
- for message in conf['messages']:
- complete_message = {'sender': self._name}
- complete_message.update(message)
- self._messages.append(complete_message)
- receives = [{'target': self._name, 'command': 'execute'}]
- sends = []
- sends.extend(receives)
- sends.extend(conf['messages'])
- self._bus.register(self._name, sends, receives, self._execute)
- super()._process_conf(conf)
-
- async def run(self) -> None:
- await super().run()
- await self._bus.send({'sender': self._name, 'target': self._name,
- 'command': 'execute'})
-
-
-class Wait(BasePlugin):
- async def _wait(self, message: Message) -> None:
- await asyncio.sleep(self._seconds)
- await self._bus.send({'sender': self._name, 'event': 'finished'})
-
- def _process_conf(self, conf: PluginConfiguration) -> None:
- self._seconds = conf['seconds']
- receives = [{'target': self._name, 'command': 'wait'}]
- sends = [{'event': 'finished'}]
- self._bus.register(self._name, sends, receives, self._wait)
- super()._process_conf(conf)
-
-
-class Alias(BasePlugin):
- async def _alias(self, message: Message) -> None:
- alias_message = {}
- alias_message['sender'] = self._name
- alias_message.update(self._to)
- for key in message:
- if key != 'sender' and key not in self._from:
- alias_message[key] = message[key]
- await self._bus.send(alias_message)
-
- def _process_conf(self, conf: PluginConfiguration) -> None:
- self._from = conf['from']
- self._to = conf['to']
- self._bus.register(self._name, [self._to], [self._from], self._alias)
- super()._process_conf(conf)
-
-
-class State(BasePlugin):
- async def _receive(self, message: Message) -> None:
- if 'command' in message:
- if message['command'] == 'get state':
- await self._bus.send({'sender': self._name,
- 'state': self._state,
- 'changed': False})
- elif message['command'] == 'set state':
- if 'state' in message and self._state != message['state']:
- self._state: bool = message['state']
- await self._bus.send({'sender': self._name,
- 'state': self._state,
- 'changed': True})
-
- def _process_conf(self, conf: PluginConfiguration) -> None:
- self._state = False
- sends: list[Message] = [{'sender': self._name, 'state': bool}]
- receives: list[Message] = [{'target': self._name,
- 'command': 'get state'},
- {'target': self._name,
- 'command': 'set state',
- 'state': bool}]
- self._bus.register(self._name, sends, receives, self._receive)
- super()._process_conf(conf)
weitere Plugin-Klassen in Python zu implementieren und (in anderen
Code-Repositories und anderen Distributions-Paketen) zum System
hinzuzufügen.
- Im Modul `controlpi.plugins.util` bzw. der Datei
- `controlpi/plugins/util.py` befindet sich eine Reihe nützlicher
+ Im Modul `controlpi-plugins.util` bzw. der Datei
+ `controlpi-plugins/util.py` befindet sich eine Reihe nützlicher
Standard-Plugins, an denen die generelle Struktur nachvollzogen werden
kann.
- Ein Nachrichten-Bus erlaubt den Austausch von Nachrichten zwischen allen
Sie müssen nicht unbedingt bestimmte Empfänger haben, sie gehören nicht
unbedingt zu einem bestimmten Typen etc.
-Einige Konventionen, die z.B. von den Plugins in `controlpi.plugins.util`
+Einige Konventionen, die z.B. von den Plugins in `controlpi-plugins.util`
eingehalten werden, sind aber:
- Einige Nachrichten signalisieren, dass ein Ereignis eingetreten ist.
Sie haben in der Regel einen Schlüssel `'event'` mit einem Wert, der die
long_description=long_description,
long_description_content_type="text/markdown",
url="http://docs.graph-it.com/graphit/controlpi",
- packages=["controlpi", "controlpi.plugins"],
+ packages=["controlpi", "controlpi-plugins"],
package_data={"controlpi": ["py.typed"]},
zip_safe=False,
extras_require={