craftbeerpi4-pione/core/extension/comp/__init__.py

34 lines
812 B
Python
Raw Normal View History

2018-11-16 20:35:59 +01:00
from core.api.decorator import on_event
from core.api.extension import CBPiExtension
class MyComp(CBPiExtension):
def __init__(self, cbpi):
'''
Initializer
:param cbpi:
'''
self.cbpi = cbpi
# register for bus events
self.cbpi.register_events(self)
@on_event(topic="actor/#")
def listen(self, **kwargs):
print("Test", kwargs)
2018-11-18 23:09:17 +01:00
@on_event(topic="kettle/+/automatic")
def listen2(self, **kwargs):
print("HANDLE AUTOMATIC", kwargs)
self.cbpi.bus.fire(topic="actor/%s/toggle" % 1, id=1)
2018-11-16 20:35:59 +01:00
def setup(cbpi):
'''
Setup method is invoked during startup
:param cbpi: the cbpi core object
:return:
'''
# regsiter the component to the core
cbpi.plugin.register("MyComp", MyComp)