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

57 lines
1.3 KiB
Python
Raw Normal View History

2019-01-05 20:43:48 +01:00
import os
from aiohttp import web
2019-01-05 20:43:48 +01:00
from cbpi.api import *
from cbpi.controller.crud_controller import CRUDController
from cbpi.database.orm_framework import DBModel
from cbpi.http_endpoints.http_curd_endpoints import HttpCrudEndpoints
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
2019-01-05 20:43:48 +01:00
class MyComp(CBPiExtension, CRUDController, HttpCrudEndpoints):
model = DummyModel
2018-11-16 20:35:59 +01:00
def __init__(self, cbpi):
'''
Initializer
:param cbpi:
'''
2019-01-05 20:43:48 +01:00
2018-11-16 20:35:59 +01:00
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
2019-01-05 20:43:48 +01:00
self.cbpi.register(self, "/dummy", static=os.path.join(os.path.dirname(__file__), "static"))
2018-11-16 20:35:59 +01:00
@on_event(topic="actor/#")
2018-12-13 21:45:33 +01:00
async def listen(self, **kwargs):
2018-12-29 00:27:19 +01:00
pass
2018-11-16 20:35:59 +01:00
2018-12-13 21:45:33 +01:00
2018-11-18 23:09:17 +01:00
@on_event(topic="kettle/+/automatic")
2018-12-13 21:45:33 +01:00
async def listen2(self, **kwargs):
2018-12-29 00:27:19 +01:00
2018-11-18 23:09:17 +01:00
2018-12-13 21:45:33 +01:00
await self.cbpi.bus.fire(topic="actor/%s/toggle" % 1, id=1)
2018-11-18 23:09:17 +01:00
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