"save props for steps"

This commit is contained in:
Manuel Fritsch 2021-03-07 23:52:20 +01:00
parent 51c8f82834
commit 7a5e852121
6 changed files with 14 additions and 27 deletions

View file

@ -1 +1 @@
__version__ = "4.0.0.30" __version__ = "4.0.0.31"

View file

@ -35,8 +35,8 @@ class Props:
else: else:
return d return d
def to_dict(self):
def to_dict(self):
def parse_object(value): def parse_object(value):
if isinstance(value, Props): if isinstance(value, Props):
return value.to_dict() return value.to_dict()
@ -48,7 +48,6 @@ class Props:
return dict((key, parse_object(value)) for (key, value) in self.__data__.items()) return dict((key, parse_object(value)) for (key, value) in self.__data__.items())
@dataclass @dataclass
class Actor: class Actor:
id: str = None id: str = None

View file

@ -67,8 +67,8 @@ class CBPiStep(CBPiBase):
async def on_props_update(self, props): async def on_props_update(self, props):
self.props = {**self.props, **props} self.props = {**self.props, **props}
async def save_props(self, props): async def save_props(self):
pass await self.cbpi.step.save()
async def push_update(self): async def push_update(self):
self.cbpi.step.push_udpate() self.cbpi.step.push_udpate()

View file

@ -37,18 +37,17 @@ class StepController:
name = data.get("name") name = data.get("name")
type = data.get("type") type = data.get("type")
status = StepState(data.get("status", "I")) status = StepState(data.get("status", "I"))
props = data.get("props", {}) props = Props(data.get("props", {}))
try: try:
type_cfg = self.types.get(type) type_cfg = self.types.get(type)
clazz = type_cfg.get("class") clazz = type_cfg.get("class")
instance = clazz(self.cbpi, id, name, props, self.done)
instance = clazz(self.cbpi, id, name, Props(props), self.done)
except Exception as e: except Exception as e:
logging.warning("Failed to create step instance %s - %s" % (id, e)) logging.warning("Failed to create step instance %s - %s" % (id, e))
instance = None 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): def load(self, startActive=False):
@ -94,7 +93,6 @@ class StepController:
try: try:
type_cfg = self.types.get(item.type) type_cfg = self.types.get(item.type)
clazz = type_cfg.get("class") clazz = type_cfg.get("class")
item.instance = clazz(self.cbpi, item.id, item.name, item.props, self.done) item.instance = clazz(self.cbpi, item.id, item.name, item.props, self.done)
except Exception as e: except Exception as e:
logging.warning("Failed to create step instance %s - %s " % (item.id, e)) logging.warning("Failed to create step instance %s - %s " % (item.id, e))
@ -139,6 +137,9 @@ class StepController:
async def next(self): async def next(self):
logging.info("Trigger Next") logging.info("Trigger Next")
print("\n\n\n\n")
print(self.profile)
print("\n\n\n\n")
step = self.find_by_status(StepState.ACTIVE) step = self.find_by_status(StepState.ACTIVE)
if step is not None: if step is not None:
if step.instance is not None: if step.instance is not None:

View file

@ -22,12 +22,6 @@ class DummyActor(CBPiActor):
await self.cbpi.step.next() 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): async def start(self):
await super().start() await super().start()

View file

@ -11,17 +11,8 @@ import logging
Property.Kettle(label="Kettle")]) Property.Kettle(label="Kettle")])
class MashStep(CBPiStep): 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): async def on_timer_done(self,timer):
self.summary = "" self.summary = ""
@ -54,6 +45,8 @@ class MashStep(CBPiStep):
self.timer.start() self.timer.start()
return StepResult.DONE return StepResult.DONE
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True)]) @parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True)])
class WaitStep(CBPiStep): class WaitStep(CBPiStep):