+"""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)