fixes for femrentersteps on controler shutdown

This commit is contained in:
avollkopf 2022-03-01 21:55:52 +01:00
parent 840d97c115
commit 5bcbb7480a
4 changed files with 35 additions and 19 deletions

View file

@ -339,7 +339,7 @@ def create():
@click.command() @click.command()
@click.argument('name') @click.argument('name')
def autostart(name): def autostart(name):
'''Enable or disable autostart''' '''(on|off|status) Enable or disable autostart'''
if(name == "status"): if(name == "status"):
if os.path.exists(os.path.join("/etc/systemd/system","craftbeerpi.service")) is True: 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)) print("CraftBeerPi Autostart is {}ON{}".format(Fore.LIGHTGREEN_EX,Style.RESET_ALL))
@ -391,7 +391,7 @@ def autostart(name):
@click.command() @click.command()
@click.argument('name') @click.argument('name')
def chromium(name): def chromium(name):
'''Enable or disable autostart''' '''(on|off|status) Enable or disable Kiosk mode'''
if(name == "status"): if(name == "status"):
if os.path.exists(os.path.join("/etc/xdg/autostart/","chromium.desktop")) is True: 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)) print("CraftBeerPi Chromium Desktop is {}ON{}".format(Fore.LIGHTGREEN_EX,Style.RESET_ALL))

View file

@ -127,6 +127,10 @@ class FermentationController:
for step in fermenter.steps: for step in fermenter.steps:
try: try:
self.logger.info("Stop {}".format(step.name)) self.logger.info("Stop {}".format(step.name))
try:
step.instance.shutdown = True
except:
pass
await step.instance.stop() await step.instance.stop()
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
@ -136,6 +140,10 @@ class FermentationController:
for step in fermenter.steps: for step in fermenter.steps:
try: try:
self.logger.info("Stop {}".format(step.name)) self.logger.info("Stop {}".format(step.name))
try:
step.instance.shutdown = True
except:
pass
await step.instance.stop() await step.instance.stop()
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
@ -156,6 +164,8 @@ class FermentationController:
name = item.get("name") name = item.get("name")
props = Props(item.get("props")) props = Props(item.get("props"))
status = StepState(item.get("status", "I")) status = StepState(item.get("status", "I"))
if status == StepState.ACTIVE:
status = StepState("S")
type = item.get("type") type = item.get("type")
try: try:
@ -399,6 +409,7 @@ class FermentationController:
logging.info("Restarting step {}".format(step.name)) logging.info("Restarting step {}".format(step.name))
step.status = StepState.ACTIVE step.status = StepState.ACTIVE
self.save() self.save()
self.push_update()
self.push_update("fermenterstepupdate") self.push_update("fermenterstepupdate")
return return
@ -411,6 +422,7 @@ class FermentationController:
logging.info("Starting step {}".format(step.name)) logging.info("Starting step {}".format(step.name))
step.status = StepState.ACTIVE step.status = StepState.ACTIVE
self.save() self.save()
self.push_update()
self.push_update("fermenterstepupdate") self.push_update("fermenterstepupdate")
except Exception as e: except Exception as e:
@ -496,7 +508,7 @@ class FermentationController:
await self.start(id) await self.start(id)
else: else:
logging.info("No Step is running") logging.info("No Step is running")
self.push_update()
self.push_update("fermenterstepupdate") self.push_update("fermenterstepupdate")
except Exception as e: except Exception as e:
@ -511,10 +523,12 @@ class FermentationController:
self.logger.info("Stopping Step {} {}".format(step.name, step.id)) self.logger.info("Stopping Step {} {}".format(step.name, step.id))
try: try:
await step.instance.stop() await step.instance.stop()
await step.instance.reset()
step.status = StepState.INITIAL step.status = StepState.INITIAL
except Exception as e: except Exception as e:
self.logger.error(e) self.logger.error(e)
self.save() self.save()
self.push_update()
self.push_update("fermenterstepupdate") self.push_update("fermenterstepupdate")
except Exception as e: except Exception as e:
@ -533,6 +547,7 @@ class FermentationController:
fermenter.steps[index], fermenter.steps[index+direction] = fermenter.steps[index+direction], fermenter.steps[index] fermenter.steps[index], fermenter.steps[index+direction] = fermenter.steps[index+direction], fermenter.steps[index]
self.save() self.save()
self.push_update()
self.push_update("fermenterstepupdate") self.push_update("fermenterstepupdate")
except Exception as e: except Exception as e:

View file

@ -75,7 +75,6 @@ class FermenterTargetTempStep(CBPiFermentationStep):
async def on_timer_done(self,timer): async def on_timer_done(self,timer):
self.summary = "" self.summary = ""
self.fermenter.target_temp = 0
await self.push_update() await self.push_update()
if self.AutoMode == True: if self.AutoMode == True:
await self.setAutoMode(False) await self.setAutoMode(False)
@ -160,23 +159,23 @@ class FermenterStep(CBPiFermentationStep):
else: else:
self.cbpi.notify(self.name, 'Timer is already running', NotificationType.WARNING) self.cbpi.notify(self.name, 'Timer is already running', NotificationType.WARNING)
@action("Add 5 Minutes to Timer", []) # @action("Add 1 Day to Timer", [])
async def add_timer(self): # async def add_timer(self):
if self.timer.is_running == True: # if self.timer.is_running == True:
self.cbpi.notify(self.name, '5 Minutes added', NotificationType.INFO) # self.cbpi.notify(self.name, '5 Minutes added', NotificationType.INFO)
await self.timer.add(300) # await self.timer.add(300)
else: # else:
self.cbpi.notify(self.name, 'Timer must be running to add time', NotificationType.WARNING) # self.cbpi.notify(self.name, 'Timer must be running to add time', NotificationType.WARNING)
async def on_timer_done(self,timer): async def on_timer_done(self,timer):
self.summary = "" self.summary = ""
self.fermenter.target_temp = 0
if self.AutoMode == True: if self.AutoMode == True:
await self.setAutoMode(False) await self.setAutoMode(False)
self.cbpi.notify(self.name, 'Step finished', NotificationType.SUCCESS) self.cbpi.notify(self.name, 'Step finished', NotificationType.SUCCESS)
await self.next(self.fermenter.id) if self.shutdown != True:
return StepResult.DONE await self.next(self.fermenter.id)
return StepResult.DONE
async def on_timer_update(self,timer, seconds): async def on_timer_update(self,timer, seconds):
@ -184,6 +183,7 @@ class FermenterStep(CBPiFermentationStep):
await self.push_update() await self.push_update()
async def on_start(self): async def on_start(self):
self.shutdown = False
timeD=int(self.props.get("TimerD", 0)) timeD=int(self.props.get("TimerD", 0))
timeH=int(self.props.get("TimerH", 0)) timeH=int(self.props.get("TimerH", 0))
timeM=int(self.props.get("TimerM", 0)) timeM=int(self.props.get("TimerM", 0))
@ -218,6 +218,7 @@ class FermenterStep(CBPiFermentationStep):
async def reset(self): async def reset(self):
self.timer = Timer(self.fermentationtime ,on_update=self.on_timer_update, on_done=self.on_timer_done) 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): async def run(self):
if self.fermenter.target_temp >= self.starttemp: if self.fermenter.target_temp >= self.starttemp:
@ -304,4 +305,4 @@ def setup(cbpi):
cbpi.plugin.register("FermenterNotificationStep", FermenterNotificationStep) cbpi.plugin.register("FermenterNotificationStep", FermenterNotificationStep)
cbpi.plugin.register("FermenterTargetTempStep", FermenterTargetTempStep) cbpi.plugin.register("FermenterTargetTempStep", FermenterTargetTempStep)
cbpi.plugin.register("FermenterStep", FermenterStep) cbpi.plugin.register("FermenterStep", FermenterStep)
cbpi.plugin.register("FermenterWaitStep", FermenterWaitStep) #cbpi.plugin.register("FermenterWaitStep", FermenterWaitStep)

View file

@ -30,13 +30,13 @@ setup(name='cbpi',
python_requires='>=3.9', python_requires='>=3.9',
install_requires=[ install_requires=[
"aiohttp==3.8.1", "aiohttp==3.7.4",
"aiohttp-auth==0.1.1", "aiohttp-auth==0.1.1",
"aiohttp-route-decorator==0.1.4", "aiohttp-route-decorator==0.1.4",
"aiohttp-security==0.4.0", "aiohttp-security==0.4.0",
"aiohttp-session==2.11.0", "aiohttp-session==2.9.0",
"aiohttp-swagger==1.0.16", "aiohttp-swagger==1.0.15",
"aiojobs==1.0.0 ", "aiojobs==0.3.0 ",
"aiosqlite==0.17.0", "aiosqlite==0.17.0",
"cryptography==36.0.1", "cryptography==36.0.1",
"requests==2.27.1", "requests==2.27.1",