From 5bcbb7480a5e55dbc59f6e0da3eb2e8d05a0d2c5 Mon Sep 17 00:00:00 2001 From: avollkopf <43980694+avollkopf@users.noreply.github.com> Date: Tue, 1 Mar 2022 21:55:52 +0100 Subject: [PATCH] fixes for femrentersteps on controler shutdown --- cbpi/cli.py | 4 ++-- cbpi/controller/fermentation_controller.py | 17 +++++++++++++- cbpi/extension/FermentationStep/__init__.py | 25 +++++++++++---------- setup.py | 8 +++---- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/cbpi/cli.py b/cbpi/cli.py index fddd71e..850b53a 100644 --- a/cbpi/cli.py +++ b/cbpi/cli.py @@ -339,7 +339,7 @@ def create(): @click.command() @click.argument('name') def autostart(name): - '''Enable or disable autostart''' + '''(on|off|status) Enable or disable autostart''' if(name == "status"): if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is True: print("CraftBeerPi Autostart is {}ON{}".format(Fore.LIGHTGREEN_EX,Style.RESET_ALL)) @@ -391,7 +391,7 @@ def autostart(name): @click.command() @click.argument('name') def chromium(name): - '''Enable or disable autostart''' + '''(on|off|status) Enable or disable Kiosk mode''' if(name == "status"): if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is True: print("CraftBeerPi Chromium Desktop is {}ON{}".format(Fore.LIGHTGREEN_EX,Style.RESET_ALL)) diff --git a/cbpi/controller/fermentation_controller.py b/cbpi/controller/fermentation_controller.py index d1ec5a2..c0134fd 100644 --- a/cbpi/controller/fermentation_controller.py +++ b/cbpi/controller/fermentation_controller.py @@ -127,6 +127,10 @@ class FermentationController: for step in fermenter.steps: try: self.logger.info("Stop {}".format(step.name)) + try: + step.instance.shutdown = True + except: + pass await step.instance.stop() except Exception as e: self.logger.error(e) @@ -136,6 +140,10 @@ class FermentationController: for step in fermenter.steps: try: self.logger.info("Stop {}".format(step.name)) + try: + step.instance.shutdown = True + except: + pass await step.instance.stop() except Exception as e: self.logger.error(e) @@ -156,6 +164,8 @@ class FermentationController: name = item.get("name") props = Props(item.get("props")) status = StepState(item.get("status", "I")) + if status == StepState.ACTIVE: + status = StepState("S") type = item.get("type") try: @@ -399,6 +409,7 @@ class FermentationController: logging.info("Restarting step {}".format(step.name)) step.status = StepState.ACTIVE self.save() + self.push_update() self.push_update("fermenterstepupdate") return @@ -411,6 +422,7 @@ class FermentationController: logging.info("Starting step {}".format(step.name)) step.status = StepState.ACTIVE self.save() + self.push_update() self.push_update("fermenterstepupdate") except Exception as e: @@ -496,7 +508,7 @@ class FermentationController: await self.start(id) else: logging.info("No Step is running") - + self.push_update() self.push_update("fermenterstepupdate") except Exception as e: @@ -511,10 +523,12 @@ class FermentationController: self.logger.info("Stopping Step {} {}".format(step.name, step.id)) try: await step.instance.stop() + await step.instance.reset() step.status = StepState.INITIAL except Exception as e: self.logger.error(e) self.save() + self.push_update() self.push_update("fermenterstepupdate") except Exception as e: @@ -533,6 +547,7 @@ class FermentationController: fermenter.steps[index], fermenter.steps[index+direction] = fermenter.steps[index+direction], fermenter.steps[index] self.save() + self.push_update() self.push_update("fermenterstepupdate") except Exception as e: diff --git a/cbpi/extension/FermentationStep/__init__.py b/cbpi/extension/FermentationStep/__init__.py index bb7b051..7660176 100644 --- a/cbpi/extension/FermentationStep/__init__.py +++ b/cbpi/extension/FermentationStep/__init__.py @@ -75,7 +75,6 @@ class FermenterTargetTempStep(CBPiFermentationStep): async def on_timer_done(self,timer): self.summary = "" - self.fermenter.target_temp = 0 await self.push_update() if self.AutoMode == True: await self.setAutoMode(False) @@ -160,23 +159,23 @@ class FermenterStep(CBPiFermentationStep): else: self.cbpi.notify(self.name, 'Timer is already running', NotificationType.WARNING) - @action("Add 5 Minutes 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, '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) async def on_timer_done(self,timer): self.summary = "" - self.fermenter.target_temp = 0 if self.AutoMode == True: await self.setAutoMode(False) self.cbpi.notify(self.name, 'Step finished', NotificationType.SUCCESS) - 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_update(self,timer, seconds): @@ -184,6 +183,7 @@ class FermenterStep(CBPiFermentationStep): await self.push_update() async def on_start(self): + self.shutdown = False timeD=int(self.props.get("TimerD", 0)) timeH=int(self.props.get("TimerH", 0)) timeM=int(self.props.get("TimerM", 0)) @@ -218,6 +218,7 @@ class FermenterStep(CBPiFermentationStep): async def reset(self): self.timer = Timer(self.fermentationtime ,on_update=self.on_timer_update, on_done=self.on_timer_done) + self.timer.is_running == False async def run(self): if self.fermenter.target_temp >= self.starttemp: @@ -304,4 +305,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("FermenterWaitStep", FermenterWaitStep) \ No newline at end of file diff --git a/setup.py b/setup.py index 5ce1179..82c23a0 100644 --- a/setup.py +++ b/setup.py @@ -30,13 +30,13 @@ setup(name='cbpi', python_requires='>=3.9', install_requires=[ - "aiohttp==3.8.1", + "aiohttp==3.7.4", "aiohttp-auth==0.1.1", "aiohttp-route-decorator==0.1.4", "aiohttp-security==0.4.0", - "aiohttp-session==2.11.0", - "aiohttp-swagger==1.0.16", - "aiojobs==1.0.0 ", + "aiohttp-session==2.9.0", + "aiohttp-swagger==1.0.15", + "aiojobs==0.3.0 ", "aiosqlite==0.17.0", "cryptography==36.0.1", "requests==2.27.1",