- Init sends list of messages on startup and on demand.
- Alias translates messages to an alias.
->>> import asyncio
>>> import controlpi
>>> asyncio.run(controlpi.test(
... {"Test Log": {"plugin": "Log",
Test Log: {'sender': 'Test Alias', 'id': 'translated',
'content': 'Test Message'}
"""
+import asyncio
+
from controlpi import BasePlugin, Message, MessageTemplate
template and are logged by the instance "Test Log", while the second
message does not match and is only logged by the test, but not by the
Log instance:
- >>> import asyncio
>>> import controlpi
>>> asyncio.run(controlpi.test(
... {"Test Log": {"plugin": "Log",
In the example, the two configured messages are sent twice, once at
startup and a second time in reaction to the "execute" command sent by
the test:
- >>> import asyncio
>>> import controlpi
>>> asyncio.run(controlpi.test(
... {"Test Init": {"plugin": "Init",
"""Send configured messages."""
for message in self.conf['messages']:
await self.bus.send(Message(self.name, message))
+ # Give immediate reactions to messages opportunity to happen:
+ await asyncio.sleep(0)
def process_conf(self) -> None:
"""Register plugin as bus client."""
In the example, the first command sent by the test sets two messages,
which are then sent in reaction to the second command sent by the test:
- >>> import asyncio
>>> import controlpi
>>> asyncio.run(controlpi.test(
... {"Test Execute": {"plugin": "Execute"}},
elif message['command'] == 'execute':
for message in self.messages:
await self.bus.send(Message(self.name, message))
+ # Give immediate reactions to messages opportunity to happen:
+ await asyncio.sleep(0)
def process_conf(self) -> None:
"""Register plugin as bus client."""
In the example, the two messages sent by the test are translated by the
Alias instance and the translated messages are sent by it preserving
the "content" keys:
- >>> import asyncio
>>> import controlpi
>>> asyncio.run(controlpi.test(
... {"Test Alias": {"plugin": "Alias",
'receives': [{'id': {'const': 42}}]}
test(): {'sender': 'test()', 'id': 42,
'content': 'Test Message'}
- test(): {'sender': 'test()', 'id': 42,
- 'content': 'Second Message'}
test(): {'sender': 'Test Alias', 'id': 'translated',
'content': 'Test Message'}
+ test(): {'sender': 'test()', 'id': 42,
+ 'content': 'Second Message'}
test(): {'sender': 'Test Alias', 'id': 'translated',
'content': 'Second Message'}