From b84e33822b378159440f2c43965f785b08015b2c Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Wed, 2 Mar 2022 17:25:59 +0100 Subject: [PATCH] added shutdown flag to all steps for on_timer_done --- cbpi/extension/FermentationStep/__init__.py | 71 ++++++--------------- 1 file changed, 19 insertions(+), 52 deletions(-) diff --git a/cbpi/extension/FermentationStep/__init__.py b/cbpi/extension/FermentationStep/__init__.py index 9f254f9..f63fb9d 100644 --- a/cbpi/extension/FermentationStep/__init__.py +++ b/cbpi/extension/FermentationStep/__init__.py @@ -32,8 +32,9 @@ class FermenterNotificationStep(CBPiFermentationStep): if self.AutoNext == True: self.cbpi.notify(self.name, self.props.get("Notification",""), NotificationType.INFO) - await self.next(self.fermenter.id) - return StepResult.DONE + if self.shutdown != True: + await self.next(self.fermenter.id) + return StepResult.DONE else: self.cbpi.notify(self.name, self.props.get("Notification",""), NotificationType.INFO, action=[NotificationAction("Next Step", self.NextStep)]) await self.push_update() @@ -42,6 +43,7 @@ class FermenterNotificationStep(CBPiFermentationStep): await self.push_update() async def on_start(self): + self.shutdown = False self.summary="" self.AutoNext = False if self.props.get("AutoNext", "No") == "No" else True if self.timer is None: @@ -69,10 +71,10 @@ class FermenterNotificationStep(CBPiFermentationStep): class FermenterTargetTempStep(CBPiFermentationStep): async def NextStep(self, **kwargs): - await self.next(self.fermenter.id) - return StepResult.DONE + if self.shutdown != True: + await self.next(self.fermenter.id) + return StepResult.DONE - async def on_timer_done(self,timer): self.summary = "" await self.push_update() @@ -87,6 +89,7 @@ class FermenterTargetTempStep(CBPiFermentationStep): await self.push_update() async def on_start(self): + self.shutdown = False self.AutoMode = True if self.props.get("AutoMode","No") == "Yes" else False self.starttemp= self.get_sensor_value(self.props.get("Sensor", None)).get("value") if self.fermenter is not None: @@ -127,6 +130,7 @@ class FermenterTargetTempStep(CBPiFermentationStep): async def reset(self): self.timer = Timer(1 ,on_update=self.on_timer_update, on_done=self.on_timer_done) + self.timer.is_running == False async def setAutoMode(self, auto_state): try: @@ -161,13 +165,15 @@ class FermenterStep(CBPiFermentationStep): else: self.cbpi.notify(self.name, 'Timer is already running', NotificationType.WARNING) - # @action("Add 1 Day to Timer", []) - # async def add_timer(self): - # if self.timer.is_running == True: - # self.cbpi.notify(self.name, '5 Minutes added', NotificationType.INFO) - # await self.timer.add(300) - # else: - # self.cbpi.notify(self.name, 'Timer must be running to add time', NotificationType.WARNING) +# @action("Add 1 Day to Timer", []) +# async def add_timer(self): +# if self.timer.is_running == True: +# self.cbpi.notify(self.name, '1 Day added', NotificationType.INFO) +# await self.timer.add(86400) +# self.endtime = self.endtime +86400 +# await self.update_endtime() +# else: +# self.cbpi.notify(self.name, 'Timer must be running to add time', NotificationType.WARNING) async def on_timer_done(self,timer): @@ -232,7 +238,6 @@ class FermenterStep(CBPiFermentationStep): await self.push_update() async def reset(self): - #await self.timer.stop() timeD=int(self.props.get("TimerD", 0)) timeH=int(self.props.get("TimerH", 0)) timeM=int(self.props.get("TimerM", 0)) @@ -280,43 +285,6 @@ class FermenterStep(CBPiFermentationStep): except Exception as e: logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e)) -@parameters([Property.Number(label="TimerD", description="Timer Days", configurable=True), - Property.Number(label="TimerH", description="Timer Hours", configurable=True), - Property.Number(label="TimerM", description="Timer Minutes", configurable=True) - ]) -class FermenterWaitStep(CBPiFermentationStep): - - async def on_timer_done(self, timer): - self.summary = "" - await self.next(self.fermenter.id) - return StepResult.DONE - - async def on_timer_update(self, timer, seconds): - self.summary = Timer.format_time(seconds) - await self.push_update() - - async def on_start(self): - timeD=int(self.props.get("TimerD", 0)) - timeH=int(self.props.get("TimerH", 0)) - timeM=int(self.props.get("TimerM", 0)) - self.fermentationtime=(timeM+(60*timeH)+(1440*timeD)) *60 - - if self.timer is None: - self.timer = Timer(self.fermentationtime, on_update=self.on_timer_update, on_done=self.on_timer_done) - self.timer.start() - - async def on_stop(self): - await self.timer.stop() - self.summary = "" - await self.push_update() - - async def reset(self): - self.timer = Timer(self.fermentationtime, on_update=self.on_timer_update, on_done=self.on_timer_done) - - async def run(self): - while self.running == True: - await asyncio.sleep(1) - return StepResult.DONE def setup(cbpi): ''' @@ -329,5 +297,4 @@ def setup(cbpi): cbpi.plugin.register("FermenterNotificationStep", FermenterNotificationStep) cbpi.plugin.register("FermenterTargetTempStep", FermenterTargetTempStep) - cbpi.plugin.register("FermenterStep", FermenterStep) - #cbpi.plugin.register("FermenterWaitStep", FermenterWaitStep) \ No newline at end of file + cbpi.plugin.register("FermenterStep", FermenterStep) \ No newline at end of file