fermentertest

This commit is contained in:
avollkopf 2022-02-17 21:42:54 +01:00
parent b8ef79d11c
commit 2cc2df0208
8 changed files with 93 additions and 36 deletions

View file

@ -1 +1 @@
__version__ = "4.0.1.17.a1"
__version__ = "4.0.1.17.a3"

View file

@ -82,6 +82,7 @@ def create_home_folder_structure():
pathlib.Path(os.path.join(".", 'config/dashboard')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/dashboard/widgets')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/recipes')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/fermenterrecipes')).mkdir(parents=True, exist_ok=True)
pathlib.Path(os.path.join(".", 'config/upload')).mkdir(parents=True, exist_ok=True)
print("Folder created")
@ -135,6 +136,12 @@ def check_for_setup():
print("Please run 'cbpi setup' before starting the server ")
print("***************************************************")
return False
# if os.path.exists(os.path.join(".", "config", "fermenterrecipes")) is False:
# print("***************************************************")
# print("CraftBeerPi fermenterrecipes folder not found: %s" % os.path.join(".", "config/fermenterrecipes"))
# print("Please run 'cbpi setup' before starting the server ")
# print("***************************************************")
# return False
backupfile = os.path.join(".", "restored_config.zip")
if os.path.exists(os.path.join(backupfile)) is True:
print("***************************************************")
@ -223,9 +230,9 @@ def plugins_add(package_name):
try:
p_metadata= metadata(package_name)
p_name=p_metadata['Name']
if p_name != package_name:
print("Error. Package name {} does not exist. Did you mean {}".format(package_name,p_name))
installation = False
#if p_name != package_name:
# print("Error. Package name {} does not exist. Did you mean {}".format(package_name,p_name))
# installation = False
except Exception as e:
print("Error. Package {} cannot be found in installed packages".format(package_name))
installation = False
@ -369,7 +376,7 @@ def plugin_create(name):
print("")
print("")
print(
"Plugin {} created! See https://craftbeerpi.gitbook.io/craftbeerpi4/development how to run your plugin ".format(
"Plugin {} created! See https://openbrewing.gitbook.io/craftbeerpi4_support/readme/development how to run your plugin ".format(
name))
print("")
print("Happy Development! Cheers")

View file

@ -204,6 +204,30 @@ class FermentationController:
return {"data": list(map(lambda x: x.to_dict(), self.data)), "types":self.get_types(), "steptypes":self.get_steptypes()}
def get_step_state(self, fermenterid=None):
if self.data == []:
#logging.info(self.data)
pass
fermentersteps=[]
steplist=list(map(lambda x: x.to_dict(), self.data))
for fermenter in steplist:
if fermenterid == fermenter.get("id"):
fermentersteps={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
logging.info(fermentersteps)
return fermentersteps
def get_fermenter_steps(self):
if self.data == []:
#logging.info(self.data)
pass
fermentersteps=[]
steplist=list(map(lambda x: x.to_dict(), self.data))
for fermenter in steplist:
fermenterstep={"id": fermenter.get("id"), "steps": fermenter.get("steps")}
fermentersteps.append(fermenterstep)
logging.info(fermentersteps)
return fermentersteps
async def get(self, id: str ):
return self._find_by_id(id)

View file

@ -198,6 +198,7 @@ class StepController:
def get_types(self):
result = {}
for key, value in self.types.items():
if "ferment" not in str(value.get("class")).lower():
result[key] = dict(name=value.get("name"), properties=value.get("properties"), actions=value.get("actions"))
return result

View file

@ -247,7 +247,7 @@ class CraftBeerPi:
f = Figlet(font='big')
logger.info("\n%s" % f.renderText("CraftBeerPi %s " % self.version))
logger.info("www.CraftBeerPi.com")
logger.info("(c) 2021 Manuel Fritsch")
logger.info("(c) 2021/2022 Manuel Fritsch / Alexander Vollkopf")
def _setup_http_index(self):
async def http_index(request):

View file

@ -62,9 +62,9 @@ class FermenterNotificationStep(CBPiFermentationStep):
@parameters([Property.Number(label="Temp", configurable=True),
Property.Sensor(label="Sensor"),
Property.Kettle(label="Kettle"),
Property.Fermenter(label="Fermenter"),
Property.Text(label="Notification",configurable = True, description = "Text for notification when Temp is reached"),
Property.Select(label="AutoMode",options=["Yes","No"], description="Switch Kettlelogic automatically on and off -> Yes")])
Property.Select(label="AutoMode",options=["Yes","No"], description="Switch Fermenterlogic automatically on and off -> Yes")])
class FermenterTargetTempStep(CBPiFermentationStep):
async def NextStep(self, **kwargs):
@ -72,7 +72,7 @@ class FermenterTargetTempStep(CBPiFermentationStep):
async def on_timer_done(self,timer):
self.summary = ""
self.kettle.target_temp = 0
self.fermenter.target_temp = 0
await self.push_update()
if self.AutoMode == True:
await self.setAutoMode(False)
@ -83,13 +83,13 @@ class FermenterTargetTempStep(CBPiFermentationStep):
async def on_start(self):
self.AutoMode = True if self.props.get("AutoMode","No") == "Yes" else False
self.kettle=self.get_kettle(self.props.get("Kettle", None))
if self.kettle is not None:
self.kettle.target_temp = int(self.props.get("Temp", 0))
self.fermenter=self.get_fermenter(self.props.get("Fermenter", None))
if self.fermenter is not None:
self.fermenter.target_temp = int(self.props.get("Temp", 0))
if self.AutoMode == True:
await self.setAutoMode(True)
self.summary = "Waiting for Target Temp"
if self.cbpi.kettle is not None and self.timer is None:
if self.cbpi.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()
@ -115,22 +115,22 @@ class FermenterTargetTempStep(CBPiFermentationStep):
async def setAutoMode(self, auto_state):
try:
if (self.kettle.instance is None or self.kettle.instance.state == False) and (auto_state is True):
await self.cbpi.kettle.toggle(self.kettle.id)
elif (self.kettle.instance.state == True) and (auto_state is False):
await self.cbpi.kettle.stop(self.kettle.id)
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.cbpi.fermenter.stop(self.fermenter.id)
await self.push_update()
except Exception as e:
logging.error("Failed to switch on KettleLogic {} {}".format(self.kettle.id, e))
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
@parameters([Property.Number(label="Timer", description="Time in Minutes", configurable=True),
Property.Number(label="Temp", configurable=True),
Property.Sensor(label="Sensor"),
Property.Kettle(label="Kettle"),
Property.Select(label="AutoMode",options=["Yes","No"], description="Switch Kettlelogic automatically on and off -> Yes")])
class FermentationStep(CBPiFermentationStep):
Property.Fermenter(label="Fermenter"),
Property.Select(label="AutoMode",options=["Yes","No"], description="Switch Fermenterlogic automatically on and off -> Yes")])
class FermenterStep(CBPiFermentationStep):
@action("Start Timer", [])
async def start_timer(self):
@ -152,7 +152,7 @@ class FermentationStep(CBPiFermentationStep):
async def on_timer_done(self,timer):
self.summary = ""
self.kettle.target_temp = 0
self.fermenter.target_temp = 0
if self.AutoMode == True:
await self.setAutoMode(False)
self.cbpi.notify(self.name, 'Step finished', NotificationType.SUCCESS)
@ -165,16 +165,16 @@ class FermentationStep(CBPiFermentationStep):
async def on_start(self):
self.AutoMode = True if self.props.get("AutoMode", "No") == "Yes" else False
self.kettle=self.get_kettle(self.props.Kettle)
if self.kettle is not None:
self.kettle.target_temp = int(self.props.get("Temp", 0))
self.fermenter=self.get_fermenter(self.props.Fermenter)
if self.fermenter is not None:
self.fermenter.target_temp = int(self.props.get("Temp", 0))
if self.AutoMode == True:
await self.setAutoMode(True)
await self.push_update()
if self.cbpi.kettle is not None and self.timer is None:
if self.cbpi.fermenter is not None and self.timer is None:
self.timer = Timer(int(self.props.get("Timer",0)) *60 ,on_update=self.on_timer_update, on_done=self.on_timer_done)
elif self.cbpi.kettle is not None:
elif self.cbpi.fermenter is not None:
try:
if self.timer.is_running == True:
self.timer.start()
@ -207,14 +207,14 @@ class FermentationStep(CBPiFermentationStep):
async def setAutoMode(self, auto_state):
try:
if (self.kettle.instance is None or self.kettle.instance.state == False) and (auto_state is True):
await self.cbpi.kettle.toggle(self.kettle.id)
elif (self.kettle.instance.state == True) and (auto_state is False):
await self.cbpi.kettle.stop(self.kettle.id)
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.cbpi.fermenter.stop(self.fermenter.id)
await self.push_update()
except Exception as e:
logging.error("Failed to switch on KettleLogic {} {}".format(self.kettle.id, e))
logging.error("Failed to switch on FermenterLogic {} {}".format(self.fermenter.id, e))
def setup(cbpi):
@ -228,4 +228,4 @@ def setup(cbpi):
cbpi.plugin.register("FermenterNotificationStep", FermenterNotificationStep)
cbpi.plugin.register("FermenterTargetTempStep", FermenterTargetTempStep)
cbpi.plugin.register("FermentationStep", FermentationStep)
cbpi.plugin.register("FermenterStep", FermenterStep)

View file

@ -415,3 +415,27 @@ class FermentationHttpEndpoints():
data = await request.json()
await self.controller.move_step(data["fermenterid"],data["stepid"], data["direction"])
return web.Response(status=204)
@request_mapping(path="/{id}/getsteps", method="GET", auth_required=False)
async def http_get_steps(self, request):
"""
---
description: Get Fermentersteps for Fermenter
tags:
- Fermenter
parameters:
- name: "id"
in: "path"
description: "Fermenter ID"
required: true
type: "integer"
format: "int64"
responses:
"200":
description: successful operation
"""
fermenterid= request.match_info['id']
response_data = self.controller.get_step_state(fermenterid)
return web.json_response(data=response_data)

View file

@ -34,6 +34,7 @@ class SystemHttpEndpoints:
sensor=self.cbpi.sensor.get_state(),
kettle=self.cbpi.kettle.get_state(),
step=self.cbpi.step.get_state(),
fermentersteps=self.cbpi.fermenter.get_fermenter_steps(),
config=self.cbpi.config.get_state(),
version=__version__)
, dumps=json_dumps)