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

53 lines
1.3 KiB
Python
Raw Normal View History

from aiohttp import web
from core.api.decorator import on_event, request_mapping
2018-11-16 20:35:59 +01:00
from core.api.extension import CBPiExtension
from core.controller.crud_controller import CRUDController
from core.database.orm_framework import DBModel
from core.http_endpoints.http_api import HttpAPI
class DummyModel(DBModel):
2018-12-08 14:21:00 +01:00
'''
Cumstom Data Model which will is stored in the database
'''
__fields__ = ["name"]
__table_name__ = "dummy"
2018-11-16 20:35:59 +01:00
class MyComp(CBPiExtension, CRUDController, HttpAPI):
model = DummyModel
2018-11-16 20:35:59 +01:00
def __init__(self, cbpi):
'''
Initializer
:param cbpi:
'''
self.cbpi = cbpi
2018-12-08 14:21:00 +01:00
# register component for http, events
# In addtion the sub folder static is exposed to access static content via http
2018-12-07 00:18:35 +01:00
self.cbpi.register(self, "/dummy", static="./core/extension/comp/static")
2018-11-16 20:35:59 +01:00
@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
2018-12-07 00:18:35 +01:00
cbpi.plugin.register("MyComp", MyComp)
pass