mirror of
https://github.com/PiBrewing/craftbeerpi4.git
synced 2024-11-23 15:38:14 +01:00
commit
c781f9cd2f
6 changed files with 145 additions and 24 deletions
|
@ -1,2 +1,3 @@
|
||||||
__version__ = "4.0.3.a2"
|
__version__ = "4.0.4.a3"
|
||||||
|
__codename__ = "Spring Break"
|
||||||
|
|
||||||
|
|
|
@ -54,10 +54,7 @@ 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
|
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)
|
||||||
|
@ -67,10 +64,7 @@ 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
|
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)
|
||||||
|
@ -305,6 +299,8 @@ class FermentationController:
|
||||||
item = self._find_by_id(id)
|
item = self._find_by_id(id)
|
||||||
# might require later check if step is active
|
# might require later check if step is active
|
||||||
item.steps = []
|
item.steps = []
|
||||||
|
item.brewname = ""
|
||||||
|
self.push_update()
|
||||||
self.save()
|
self.save()
|
||||||
self.push_update("fermenterstepupdate")
|
self.push_update("fermenterstepupdate")
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ from cbpi.controller.notification_controller import NotificationController
|
||||||
import logging
|
import logging
|
||||||
from os import urandom
|
from os import urandom
|
||||||
import os
|
import os
|
||||||
from cbpi import __version__
|
from cbpi import __version__, __codename__
|
||||||
from aiohttp import web
|
from aiohttp import web
|
||||||
from aiohttp_auth import auth
|
from aiohttp_auth import auth
|
||||||
from aiohttp_session import session_middleware
|
from aiohttp_session import session_middleware
|
||||||
|
@ -95,6 +95,7 @@ class CraftBeerPi:
|
||||||
self.path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1]) # The path to the package dir
|
self.path = os.sep.join(os.path.abspath(__file__).split(os.sep)[:-1]) # The path to the package dir
|
||||||
|
|
||||||
self.version = __version__
|
self.version = __version__
|
||||||
|
self.codename = __codename__
|
||||||
|
|
||||||
self.static_config = load_config(os.path.join(".", 'config', "config.yaml"))
|
self.static_config = load_config(os.path.join(".", 'config', "config.yaml"))
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ class FermenterTargetTempStep(CBPiFermentationStep):
|
||||||
if self.AutoMode == True:
|
if self.AutoMode == True:
|
||||||
await self.setAutoMode(False)
|
await self.setAutoMode(False)
|
||||||
self.cbpi.notify(self.name, self.props.get("Notification","Target Temp reached. Please add malt and klick next to move on."))
|
self.cbpi.notify(self.name, self.props.get("Notification","Target Temp reached. Please add malt and klick next to move on."))
|
||||||
|
if self.shutdown == False:
|
||||||
await self.next(self.fermenter.id)
|
await self.next(self.fermenter.id)
|
||||||
return StepResult.DONE
|
return StepResult.DONE
|
||||||
|
|
||||||
|
@ -183,7 +184,7 @@ class FermenterStep(CBPiFermentationStep):
|
||||||
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)
|
||||||
if self.shutdown != True:
|
if self.shutdown == False:
|
||||||
await self.next(self.fermenter.id)
|
await self.next(self.fermenter.id)
|
||||||
return StepResult.DONE
|
return StepResult.DONE
|
||||||
|
|
||||||
|
@ -291,6 +292,119 @@ class FermenterStep(CBPiFermentationStep):
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
|
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
|
||||||
|
|
||||||
|
@parameters([Property.Number(label="Temp", configurable=True, description = "Ramp to this temp"),
|
||||||
|
Property.Number(label="RampRate", configurable=True, description = "Ramp x °C/F per day. Default: 1"),
|
||||||
|
Property.Sensor(label="Sensor"),
|
||||||
|
Property.Text(label="Notification",configurable = True, description = "Text for notification when Temp is reached"),
|
||||||
|
Property.Select(label="AutoMode",options=["Yes","No"], description="Switch Fermenterlogic automatically on and off -> Yes")])
|
||||||
|
class FermenterRampTempStep(CBPiFermentationStep):
|
||||||
|
|
||||||
|
async def NextStep(self, **kwargs):
|
||||||
|
if self.shutdown == False:
|
||||||
|
await self.next(self.fermenter.id)
|
||||||
|
return StepResult.DONE
|
||||||
|
|
||||||
|
async def on_timer_done(self,timer):
|
||||||
|
self.summary = ""
|
||||||
|
await self.push_update()
|
||||||
|
if self.AutoMode == True:
|
||||||
|
await self.setAutoMode(False)
|
||||||
|
self.cbpi.notify(self.name, self.props.get("Notification","Target Temp reached. Please add malt and klick next to move on."))
|
||||||
|
await self.next(self.fermenter.id)
|
||||||
|
return StepResult.DONE
|
||||||
|
|
||||||
|
|
||||||
|
async def on_timer_update(self,timer, seconds):
|
||||||
|
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.rate=float(self.props.get("RampRate",1))
|
||||||
|
logging.info(self.rate)
|
||||||
|
self.target_temp = round(float(self.props.get("Temp", 0))*10)/10
|
||||||
|
logging.info(self.target_temp)
|
||||||
|
while self.get_sensor_value(self.props.get("Sensor", None)).get("value") > 900:
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
self.starttemp = self.get_sensor_value(self.props.get("Sensor", None)).get("value")
|
||||||
|
|
||||||
|
self.current_target_temp = self.starttemp
|
||||||
|
if self.fermenter is not None:
|
||||||
|
await self.set_fermenter_target_temp(self.fermenter.id, self.current_target_temp)
|
||||||
|
if self.AutoMode == True:
|
||||||
|
await self.setAutoMode(True)
|
||||||
|
self.summary = "Ramping to {}° with {}° per day".format(self.target_temp,self.rate)
|
||||||
|
if self.fermenter is not None and self.timer is None:
|
||||||
|
self.timer = Timer(1 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
|
||||||
|
await self.push_update()
|
||||||
|
|
||||||
|
async def on_stop(self):
|
||||||
|
await self.timer.stop()
|
||||||
|
self.summary = ""
|
||||||
|
if self.AutoMode == True:
|
||||||
|
await self.setAutoMode(False)
|
||||||
|
await self.push_update()
|
||||||
|
|
||||||
|
async def calc_target_temp(self):
|
||||||
|
delta_time = time.time() - self.starttime
|
||||||
|
current_target_temp = round((self.starttemp + delta_time * self.ratesecond)*10)/10
|
||||||
|
# logging.info(current_target_temp)
|
||||||
|
if current_target_temp != self.current_target_temp:
|
||||||
|
self.current_target_temp = current_target_temp
|
||||||
|
await self.set_fermenter_target_temp(self.fermenter.id, self.current_target_temp)
|
||||||
|
#self.fermenter.target_temp = self.current_target_temp
|
||||||
|
await self.push_update()
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
||||||
|
async def run(self):
|
||||||
|
self.delta_temp = self.target_temp-self.starttemp
|
||||||
|
try:
|
||||||
|
self.deltadays = abs(self.delta_temp / self.rate)
|
||||||
|
self.deltaseconds = self.deltadays * 24 * 60 * 60
|
||||||
|
self.ratesecond = self.delta_temp/self.deltaseconds
|
||||||
|
except Exception as e:
|
||||||
|
logging.info(e)
|
||||||
|
self.starttime=time.time()
|
||||||
|
|
||||||
|
if self.target_temp >= self.starttemp:
|
||||||
|
logging.info("warmup")
|
||||||
|
while self.running == True:
|
||||||
|
if self.current_target_temp != self.target_temp:
|
||||||
|
await self.calc_target_temp()
|
||||||
|
sensor_value = self.get_sensor_value(self.props.get("Sensor", None)).get("value")
|
||||||
|
if sensor_value >= self.target_temp and self.timer.is_running is not True:
|
||||||
|
self.timer.start()
|
||||||
|
self.timer.is_running = True
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
elif self.target_temp <= self.starttemp:
|
||||||
|
logging.info("Cooldown")
|
||||||
|
while self.running == True:
|
||||||
|
if self.current_target_temp != self.target_temp:
|
||||||
|
await self.calc_target_temp()
|
||||||
|
sensor_value = self.get_sensor_value(self.props.get("Sensor", None)).get("value")
|
||||||
|
if sensor_value <= self.target_temp and self.timer.is_running is not True:
|
||||||
|
self.timer.start()
|
||||||
|
self.timer.is_running = True
|
||||||
|
await asyncio.sleep(1)
|
||||||
|
await self.push_update()
|
||||||
|
return StepResult.DONE
|
||||||
|
|
||||||
|
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:
|
||||||
|
if (self.fermenter.instance is None or self.fermenter.instance.state == False) and (auto_state is True):
|
||||||
|
await self.cbpi.fermenter.toggle(self.fermenter.id)
|
||||||
|
elif (self.fermenter.instance.state == True) and (auto_state is False):
|
||||||
|
await self.fermenter.instance.stop()
|
||||||
|
await self.push_update()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
|
||||||
|
|
||||||
|
|
||||||
def setup(cbpi):
|
def setup(cbpi):
|
||||||
'''
|
'''
|
||||||
|
@ -303,4 +417,5 @@ 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("FermenterRampTempStep", FermenterRampTempStep)
|
||||||
cbpi.plugin.register("FermenterStep", FermenterStep)
|
cbpi.plugin.register("FermenterStep", FermenterStep)
|
||||||
|
|
|
@ -5,7 +5,7 @@ from cbpi.job.aiohttp import get_scheduler_from_app
|
||||||
import logging
|
import logging
|
||||||
from cbpi.api import request_mapping
|
from cbpi.api import request_mapping
|
||||||
from cbpi.utils import json_dumps
|
from cbpi.utils import json_dumps
|
||||||
from cbpi import __version__
|
from cbpi import __version__, __codename__
|
||||||
import pathlib
|
import pathlib
|
||||||
import os
|
import os
|
||||||
from cbpi.controller.system_controller import SystemController
|
from cbpi.controller.system_controller import SystemController
|
||||||
|
@ -36,7 +36,8 @@ class SystemHttpEndpoints:
|
||||||
step=self.cbpi.step.get_state(),
|
step=self.cbpi.step.get_state(),
|
||||||
fermentersteps=self.cbpi.fermenter.get_fermenter_steps(),
|
fermentersteps=self.cbpi.fermenter.get_fermenter_steps(),
|
||||||
config=self.cbpi.config.get_state(),
|
config=self.cbpi.config.get_state(),
|
||||||
version=__version__)
|
version=__version__,
|
||||||
|
codename=__codename__)
|
||||||
, dumps=json_dumps)
|
, dumps=json_dumps)
|
||||||
|
|
||||||
@request_mapping(path="/logs", auth_required=False)
|
@request_mapping(path="/logs", auth_required=False)
|
||||||
|
|
17
release.py
17
release.py
|
@ -1,3 +1,4 @@
|
||||||
|
import code
|
||||||
import subprocess
|
import subprocess
|
||||||
import click
|
import click
|
||||||
import re
|
import re
|
||||||
|
@ -10,16 +11,22 @@ def main():
|
||||||
@click.option('-m', prompt='Commit Message')
|
@click.option('-m', prompt='Commit Message')
|
||||||
def commit(m):
|
def commit(m):
|
||||||
|
|
||||||
|
new_content = []
|
||||||
file = "./cbpi/__init__.py"
|
file = "./cbpi/__init__.py"
|
||||||
with open(file) as reader:
|
with open(file) as reader:
|
||||||
match = re.search('.*\"(.*)\"', reader.readline())
|
match = re.search('.*\"(.*)\"', reader.readline())
|
||||||
|
codename = reader.readline()
|
||||||
|
try:
|
||||||
major, minor, patch, build = match.group(1).split(".")
|
major, minor, patch, build = match.group(1).split(".")
|
||||||
build = int(build)
|
except:
|
||||||
build += 1
|
major, minor, patch = match.group(1).split(".")
|
||||||
new_version = "__version__ = \"{}.{}.{}.{}\"".format(major,minor,patch, build)
|
patch = int(patch)
|
||||||
|
patch += 1
|
||||||
|
new_content.append("__version__ = \"{}.{}.{}\"".format(major,minor,patch))
|
||||||
|
new_content.append(codename)
|
||||||
with open(file,'w',encoding = 'utf-8') as file:
|
with open(file,'w',encoding = 'utf-8') as file:
|
||||||
print("New Version {}.{}.{}.{}".format(major,minor,patch, build))
|
print("New Version {}.{}.{}".format(major,minor,patch))
|
||||||
file.write(new_version)
|
file.writelines("%s\n" % i for i in new_content)
|
||||||
|
|
||||||
subprocess.run(["git", "add", "-A"])
|
subprocess.run(["git", "add", "-A"])
|
||||||
subprocess.run(["git", "commit", "-m", "\"{}\"".format(m)])
|
subprocess.run(["git", "commit", "-m", "\"{}\"".format(m)])
|
||||||
|
|
Loading…
Reference in a new issue