From de6923d572102d9113b39813aa29a1ad45c72008 Mon Sep 17 00:00:00 2001 From: manuel83 Date: Thu, 6 Dec 2018 23:46:06 +0100 Subject: [PATCH] test of dummy component with custom data model. Action handler for step controller --- .../5067e7fe-480d-4433-bc40-f2d1c38362a2.xml | 171 ++--- .idea/workspace.xml | 630 ++++++------------ core/api/step.py | 2 +- core/controller/plugin_controller.py | 5 +- core/controller/step_controller.py | 14 + core/craftbeerpi.py | 2 + core/extension/comp/__init__.py | 28 +- core/extension/dummystep/__init__.py | 12 +- core/sql/create_table_user.sql | 7 + craftbeerpi.db | Bin 49152 -> 53248 bytes 10 files changed, 367 insertions(+), 504 deletions(-) diff --git a/.idea/dataSources/5067e7fe-480d-4433-bc40-f2d1c38362a2.xml b/.idea/dataSources/5067e7fe-480d-4433-bc40-f2d1c38362a2.xml index d63ecaa..5945e2b 100644 --- a/.idea/dataSources/5067e7fe-480d-4433-bc40-f2d1c38362a2.xml +++ b/.idea/dataSources/5067e7fe-480d-4433-bc40-f2d1c38362a2.xml @@ -10,304 +10,317 @@
-
-
-
-
-
-
- +
+
+
+
+
+
+
+ INTEGER|0 1 - + 1 VARCHAR(80)|0 - + 2 VARCHAR(80)|0 - + 3 VARCHAR(3000)|0 - + id 1 - + VARCHAR(50)|0 1 - + 1 VARCHAR(255)|0 - + 2 VARCHAR(50)|0 - + 3 VARCHAR(255)|0 - + 4 VARCHAR(255)|0 - + name 1 - + name 1 sqlite_autoindex_config_1 - + INTEGER|0 1 - + 1 VARCHAR(80)|0 - + id 1 - + INTEGER|0 1 - + 1 INTEGER(80)|0 - + 2 INTEGER|0 - + 3 VARCHAR(80)|0 - + 4 INTEGER(5)|0 - + 5 INTEGER(5)|0 - + 6 VARCHAR(3000)|0 - + id 1 - + INTEGER|0 1 - + 1 VARCHAR(80)|0 - + + id + 1 + + + INTEGER|0 + 1 + + + 1 + VARCHAR(80)|0 + + 2 VARCHAR(80)|0 - + 3 VARCHAR(10)|0 - + 4 VARCHAR(255)|0 - + 5 VARCHAR(50)|0 - + 6 VARCHAR(1000)|0 - + 7 VARCHAR(10)|0 - + 8 INTEGER|0 - + 9 INTEGER|0 - + 10 INTEGER|0 - + id 1 - + INTEGER|0 1 - + 1 VARCHAR(80)|0 - + 2 VARCHAR(80)|0 - + 3 VARCHAR(3000)|0 - + id 1 - + text|0 - + 1 text|0 - + 2 text|0 - + 3 integer|0 - + 4 text|0 - + INTEGER|0 1 - + 1 INTEGER|0 - + 2 VARCHAR(80)|0 - + 3 VARCHAR(100)|0 - + 4 VARCHAR(255)|0 - + 5 VARCHAR(1)|0 - + 6 INTEGER|0 - + 7 INTEGER|0 - + 8 VARCHAR(255)|0 - + 9 INTEGER|0 - + id 1 - + INTEGER|0 1 - + 1 VARCHAR(80)|0 - + 2 VARCHAR(80)|0 - + 3 VARCHAR(80)|0 - + 4 VARCHAR(80)|0 - + 5 VARCHAR(80)|0 - + 6 VARCHAR(10)|0 - + 7 VARCHAR(50)|0 - + 8 VARCHAR(1000)|0 - + 9 VARCHAR(10)|0 - + 10 INTEGER|0 - + id 1 - + VARCHAR(3)|0 1 - + 1 VARCHAR(80)|0 1 - + 2 VARCHAR(100)|0 1 - + language_code key 1 - + language_code key 1 diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 5b5b60a..f201c04 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,12 +2,16 @@ + + + - + + @@ -80,11 +66,11 @@ - + - - + + @@ -95,8 +81,8 @@ - - + + @@ -104,23 +90,11 @@ - - - - - - - - - - - - - - + + @@ -128,69 +102,86 @@ - - - - - - - - - - - - + + - - + + - - + + - - + - - + + - - + + - - + + + + + + + + + + + + + + + + + - - + + - + + + + + + - - + + - - - - - + + + + + + + + + + + + + @@ -206,8 +197,6 @@ - 0x10d622b38 - 0x10bde4548 0x10d622b380x10d622b38 __init__ 0x1048b31d0 @@ -235,6 +224,8 @@ l logger logging + dummy + /dumy StepBase @@ -254,8 +245,6 @@ @@ -361,28 +352,6 @@ + - @@ -1342,10 +1129,11 @@ + - + @@ -1406,60 +1194,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1678,14 +1412,6 @@ - - - - - - - - @@ -1743,14 +1469,6 @@ - - - - - - - - @@ -1759,16 +1477,6 @@ - - - - - - - - - - @@ -1779,26 +1487,6 @@ - - - - - - - - - - - - - - - - - - - - @@ -1815,14 +1503,6 @@ - - - - - - - - @@ -1834,10 +1514,18 @@ - + - - + + + + + + + + + + @@ -1846,13 +1534,129 @@ - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/core/api/step.py b/core/api/step.py index 46a8f72..4650beb 100644 --- a/core/api/step.py +++ b/core/api/step.py @@ -27,7 +27,7 @@ class Step(object): async def _run(self): i = 0 - while i < 5: + while i < 20: try: await self.run() except Exception as e: diff --git a/core/controller/plugin_controller.py b/core/controller/plugin_controller.py index 994bb56..585b830 100644 --- a/core/controller/plugin_controller.py +++ b/core/controller/plugin_controller.py @@ -105,8 +105,9 @@ class PluginController(): if issubclass(clazz, Step): self.cbpi.step.types[name] = self._parse_props(clazz) print(self.cbpi.step.types) - #if issubclass(clazz, CBPiExtension): - # self.c = clazz(self.cbpi) + if issubclass(clazz, CBPiExtension): + self.c = clazz(self.cbpi) + self.cbpi.register(self.c, "/dummy") def _parse_props(self, cls): diff --git a/core/controller/step_controller.py b/core/controller/step_controller.py index 1688105..7280551 100644 --- a/core/controller/step_controller.py +++ b/core/controller/step_controller.py @@ -20,6 +20,12 @@ class StepController(): #self.start() pass + @request_mapping(path="/action", auth_required=False) + async def http_action(self, request): + self.cbpi.bus.fire("step/action", action="test") + return web.Response(text="OK") + + @request_mapping(path="/start", auth_required=False) async def http_start(self, request): self.cbpi.bus.fire("step/start") @@ -30,6 +36,14 @@ class StepController(): self.cbpi.bus.fire("step/reset") return web.Response(text="OK") + @on_event("step/action") + def handle_action(self, topic, action, **kwargs): + print("process action") + if self.current_step is not None: + self.current_step.__getattribute__(action)() + pass + + @on_event("step/start") def handle_start(self, topic, **kwargs): self.start() diff --git a/core/craftbeerpi.py b/core/craftbeerpi.py index daf4e3e..09f5edc 100644 --- a/core/craftbeerpi.py +++ b/core/craftbeerpi.py @@ -13,6 +13,7 @@ from aiohttp_swagger import setup_swagger from core.controller.config_controller import ConfigController from core.controller.kettle_controller import KettleController from core.controller.step_controller import StepController +from core.extension.comp import MyComp from core.job.aiohttp import setup, get_scheduler_from_app from core.controller.actor_controller import ActorController @@ -61,6 +62,7 @@ class CraftBeerPi(): self.kettle = KettleController(self) self.step = StepController(self) self.notification = NotificationController(self) + self.dummy = MyComp(self) self.login = Login(self) diff --git a/core/extension/comp/__init__.py b/core/extension/comp/__init__.py index 7c15b59..7c589ce 100644 --- a/core/extension/comp/__init__.py +++ b/core/extension/comp/__init__.py @@ -1,7 +1,19 @@ -from core.api.decorator import on_event -from core.api.extension import CBPiExtension +from aiohttp import web -class MyComp(CBPiExtension): +from core.api.decorator import on_event, request_mapping +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): + __fields__ = ["name"] + __table_name__ = "dummy" + + +class MyComp(CBPiExtension, CRUDController, HttpAPI): + model = DummyModel def __init__(self, cbpi): ''' @@ -11,7 +23,9 @@ class MyComp(CBPiExtension): ''' self.cbpi = cbpi # register for bus events - self.cbpi.register_events(self) + self.cbpi.register(self, "/dummy") + + @on_event(topic="actor/#") def listen(self, **kwargs): @@ -23,6 +37,9 @@ class MyComp(CBPiExtension): self.cbpi.bus.fire(topic="actor/%s/toggle" % 1, id=1) + + + def setup(cbpi): ''' Setup method is invoked during startup @@ -31,4 +48,5 @@ def setup(cbpi): :return: ''' # regsiter the component to the core - cbpi.plugin.register("MyComp", MyComp) \ No newline at end of file + #cbpi.plugin.register("MyComp", MyComp) + pass \ No newline at end of file diff --git a/core/extension/dummystep/__init__.py b/core/extension/dummystep/__init__.py index 015c3c6..4b8cef8 100644 --- a/core/extension/dummystep/__init__.py +++ b/core/extension/dummystep/__init__.py @@ -1,18 +1,22 @@ import asyncio -from core.api import Property +from core.api import Property, action from core.api.step import Step class CustomStep(Step): name = Property.Number(label="Test") - + _interval = 1 + + @action(key="name", parameters=None) + def test(self, **kwargs): + self.name="WOOHOO" async def run(self): - self.name = "HELLO WORLD" + #await asyncio.sleep(1) - raise Exception("OH O") + print("RUN STEP", self.id, self.name, self.__dict__) diff --git a/core/sql/create_table_user.sql b/core/sql/create_table_user.sql index 8d65c4d..a341e38 100644 --- a/core/sql/create_table_user.sql +++ b/core/sql/create_table_user.sql @@ -101,4 +101,11 @@ CREATE TABLE IF NOT EXISTS translation key VARCHAR(80) NOT NULL, text VARCHAR(100) NOT NULL, PRIMARY KEY (language_code, key) +); + +CREATE TABLE IF NOT EXISTS dummy +( + id INTEGER PRIMARY KEY NOT NULL, + name VARCHAR(80) + ); \ No newline at end of file diff --git a/craftbeerpi.db b/craftbeerpi.db index 18711b13d1721eb4484745bc48071f6b243de141..b8ae745f74768540c56054b5ee3864e9292e549d 100644 GIT binary patch delta 150 zcmZo@U~X8zJV9E}pMima7l>hiYod;^sy~Ast0OND2Llhg9|M0E-vr*Tyx}|o+!EZk zxfnQhv+v+&VfWiO@f4eO1`oTqxHw~@eo10dPHIYNZf+%*;B^jibqsM;2yt}saa8~d pO+LtPzj+6{$Bsz~ENqPY-x&D6Z59-G!_URR$jl%f?(gs64*G%&}