From 7a5e852121df82b3043d867fe8c39ed3f18bdcce Mon Sep 17 00:00:00 2001 From: Manuel Fritsch Date: Sun, 7 Mar 2021 23:52:20 +0100 Subject: [PATCH] "save props for steps" --- cbpi/__init__.py | 2 +- cbpi/api/dataclasses.py | 5 ++--- cbpi/api/step.py | 4 ++-- cbpi/controller/step_controller.py | 11 ++++++----- cbpi/extension/dummyactor/__init__.py | 6 ------ cbpi/extension/mashstep/__init__.py | 13 +++---------- 6 files changed, 14 insertions(+), 27 deletions(-) diff --git a/cbpi/__init__.py b/cbpi/__init__.py index 694f190..69ec4a5 100644 --- a/cbpi/__init__.py +++ b/cbpi/__init__.py @@ -1 +1 @@ -__version__ = "4.0.0.30" \ No newline at end of file +__version__ = "4.0.0.31" \ No newline at end of file diff --git a/cbpi/api/dataclasses.py b/cbpi/api/dataclasses.py index ce7b716..f866d46 100644 --- a/cbpi/api/dataclasses.py +++ b/cbpi/api/dataclasses.py @@ -34,9 +34,9 @@ class Props: return self.__data__[key] else: return d - - def to_dict(self): + + def to_dict(self): def parse_object(value): if isinstance(value, Props): return value.to_dict() @@ -48,7 +48,6 @@ class Props: return dict((key, parse_object(value)) for (key, value) in self.__data__.items()) - @dataclass class Actor: id: str = None diff --git a/cbpi/api/step.py b/cbpi/api/step.py index 5f9dab2..0f099ca 100644 --- a/cbpi/api/step.py +++ b/cbpi/api/step.py @@ -67,8 +67,8 @@ class CBPiStep(CBPiBase): async def on_props_update(self, props): self.props = {**self.props, **props} - async def save_props(self, props): - pass + async def save_props(self): + await self.cbpi.step.save() async def push_update(self): self.cbpi.step.push_udpate() diff --git a/cbpi/controller/step_controller.py b/cbpi/controller/step_controller.py index dab3a37..081f9cc 100644 --- a/cbpi/controller/step_controller.py +++ b/cbpi/controller/step_controller.py @@ -37,18 +37,17 @@ class StepController: name = data.get("name") type = data.get("type") status = StepState(data.get("status", "I")) - props = data.get("props", {}) + props = Props(data.get("props", {})) try: type_cfg = self.types.get(type) clazz = type_cfg.get("class") - - instance = clazz(self.cbpi, id, name, Props(props), self.done) + instance = clazz(self.cbpi, id, name, props, self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s" % (id, e)) instance = None - return Step(id, name, type=type, status=status, instance=instance, props=Props(props) ) + return Step(id, name, type=type, status=status, instance=instance, props=props ) def load(self, startActive=False): @@ -94,7 +93,6 @@ class StepController: try: type_cfg = self.types.get(item.type) clazz = type_cfg.get("class") - item.instance = clazz(self.cbpi, item.id, item.name, item.props, self.done) except Exception as e: logging.warning("Failed to create step instance %s - %s " % (item.id, e)) @@ -139,6 +137,9 @@ class StepController: async def next(self): logging.info("Trigger Next") + print("\n\n\n\n") + print(self.profile) + print("\n\n\n\n") step = self.find_by_status(StepState.ACTIVE) if step is not None: if step.instance is not None: diff --git a/cbpi/extension/dummyactor/__init__.py b/cbpi/extension/dummyactor/__init__.py index 1bb003d..f0c5ab4 100644 --- a/cbpi/extension/dummyactor/__init__.py +++ b/cbpi/extension/dummyactor/__init__.py @@ -21,13 +21,7 @@ class DummyActor(CBPiActor): print("YES!") await self.cbpi.step.next() - - @action("HELLO WORLD", {}) - async def helloWorld(self, **kwargs): - print("HELLO WORLD") - self.cbpi.notify(title="HELLO WORLD", message="DO YOU WANT TO START THE NEXT STEP", action=[NotificationAction("YES", self.yes), NotificationAction("NO")]) - async def start(self): await super().start() diff --git a/cbpi/extension/mashstep/__init__.py b/cbpi/extension/mashstep/__init__.py index 10fbc05..29e7dd9 100644 --- a/cbpi/extension/mashstep/__init__.py +++ b/cbpi/extension/mashstep/__init__.py @@ -11,18 +11,9 @@ import logging Property.Kettle(label="Kettle")]) class MashStep(CBPiStep): - @action(key="Custom RESET", parameters=[]) - async def custom_reset(self, **kwargs): - self.summary = "" - await self.push_update() + - - @action(key="Custom Action", parameters=[Property.Number(label="Value", configurable=True)]) - async def custom_action(self, Value, **kwargs): - self.summary = "VALUE FROM ACTION {}".format(Value) - await self.push_update() - async def on_timer_done(self,timer): self.summary = "" await self.next() @@ -54,6 +45,8 @@ class MashStep(CBPiStep): self.timer.start() return StepResult.DONE + + @parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True)]) class WaitStep(CBPiStep):