mirror of
https://github.com/Manuel83/craftbeerpi3
synced 2026-08-10 02:55:27 +02:00
-fix beer xml
-fix fermenter hysteresis
This commit is contained in:
@@ -6,10 +6,10 @@ from modules.core.props import Property
|
||||
@cbpi.fermentation_controller
|
||||
class Hysteresis(FermenterController):
|
||||
|
||||
heater_offset_min = Property.Number("Heater Offset min", True, 0)
|
||||
heater_offset_max = Property.Number("Heater Offset max", True, 0)
|
||||
cooler_offset_min = Property.Number("Cooler Offset min", True, 0)
|
||||
cooler_offset_max = Property.Number("Cooler Offset max", True, 0)
|
||||
heater_offset_min = Property.Number("Heater Offset ON", True, 0)
|
||||
heater_offset_max = Property.Number("Heater Offset OFF", True, 0)
|
||||
cooler_offset_min = Property.Number("Cooler Offset OFF", True, 0)
|
||||
cooler_offset_max = Property.Number("Cooler Offset ON", True, 0)
|
||||
|
||||
def stop(self):
|
||||
super(FermenterController, self).stop()
|
||||
@@ -23,16 +23,16 @@ class Hysteresis(FermenterController):
|
||||
target_temp = self.get_target_temp()
|
||||
temp = self.get_temp()
|
||||
|
||||
if temp + float(self.heater_offset_min) < target_temp:
|
||||
if temp + float(self.heater_offset_min) <= target_temp:
|
||||
self.heater_on(100)
|
||||
|
||||
if temp + float(self.heater_offset_max) > target_temp:
|
||||
if temp + float(self.heater_offset_max) >= target_temp:
|
||||
self.heater_off()
|
||||
|
||||
if temp > target_temp + float(self.cooler_offset_min):
|
||||
if temp >= target_temp + float(self.cooler_offset_min):
|
||||
self.cooler_on(100)
|
||||
|
||||
if temp < target_temp + float(self.cooler_offset_max):
|
||||
if temp <= target_temp + float(self.cooler_offset_max):
|
||||
self.cooler_off()
|
||||
|
||||
self.sleep(1)
|
||||
|
||||
@@ -10,23 +10,21 @@ import os
|
||||
from modules.steps import Step,StepView
|
||||
import xml.etree.ElementTree
|
||||
|
||||
|
||||
class BeerXMLImport(FlaskView):
|
||||
|
||||
BEER_XML_FILE = "./upload/beer.xml"
|
||||
|
||||
@route('/', methods=['GET'])
|
||||
def get(self):
|
||||
if not os.path.exists(self.BEER_XML_FILE):
|
||||
self.api.notify(headline="File Not Found", message="Please upload a Beer.xml File",
|
||||
type="danger")
|
||||
return ('', 404)
|
||||
|
||||
result = []
|
||||
for idx, r in enumerate(self.getDict().get("RECIPES").get("RECIPE")):
|
||||
result.append({"id": idx, "name": r.get("NAME")})
|
||||
return json.dumps(result)
|
||||
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
result = []
|
||||
for idx, val in enumerate(e.findall('RECIPE')):
|
||||
result.append({"id": idx+1, "name": val.find("NAME").text})
|
||||
return json.dumps(result)
|
||||
|
||||
def allowed_file(self, filename):
|
||||
return '.' in filename and filename.rsplit('.', 1)[1] in set(['xml'])
|
||||
@@ -48,12 +46,11 @@ class BeerXMLImport(FlaskView):
|
||||
@route('/<int:id>', methods=['POST'])
|
||||
def load(self, id):
|
||||
|
||||
recipe = self.getDict().get("RECIPES").get("RECIPE")[id]
|
||||
steps = recipe.get("MASH",{}).get("MASH_STEPS",{}).get("MASH_STEP",[])
|
||||
name = recipe.get("NAME")
|
||||
|
||||
steps = self.getSteps(id)
|
||||
name = self.getRecipeName(id)
|
||||
self.api.set_config_parameter("brew_name", name)
|
||||
boil_time = recipe.get("BOIL_TIME", 90)
|
||||
boil_time = self.getBoilTime(id)
|
||||
mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
|
||||
mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)
|
||||
|
||||
@@ -65,43 +62,38 @@ class BeerXMLImport(FlaskView):
|
||||
Step.delete_all()
|
||||
StepView().reset()
|
||||
|
||||
conn = None
|
||||
try:
|
||||
conn = sqlite3.connect(self.api.app.config['UPLOAD_FOLDER'] + '/kbh.db')
|
||||
c = conn.cursor()
|
||||
|
||||
for row in steps:
|
||||
Step.insert(**{"name": row.get("NAME"), "type": mashstep_type, "config": {"kettle": mash_kettle, "temp": float(row.get("STEP_TEMP")), "timer": row.get("STEP_TIME")}})
|
||||
Step.insert(**{"name": row.get("name"), "type": mashstep_type, "config": {"kettle": mash_kettle, "temp": float(row.get("temp")), "timer": row.get("timer")}})
|
||||
Step.insert(**{"name": "ChilStep", "type": "ChilStep", "config": {"timer": 15}})
|
||||
## Add cooking step
|
||||
Step.insert(**{"name": "Boil", "type": boilstep_type, "config": {"kettle": boil_kettle, "temp": boil_temp, "timer": boil_time}})
|
||||
## Add Whirlpool step
|
||||
Step.insert(**{"name": "Whirlpool", "type": "ChilStep", "config": {"timer": 15}})
|
||||
# setBrewName(name)
|
||||
self.api.emit("UPDATE_ALL_STEPS", Step.get_all())
|
||||
self.api.notify(headline="Recipe %s loaded successfully" % name, message="")
|
||||
except Exception as e:
|
||||
self.api.notify(headline="Failed to load Recipe", message=e.message, type="danger")
|
||||
return ('', 500)
|
||||
finally:
|
||||
if conn:
|
||||
conn.close()
|
||||
|
||||
return ('', 204)
|
||||
|
||||
def getRecipeName(self, id):
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
return e.find('./RECIPE[%s]/NAME' % (str(id))).text
|
||||
|
||||
def getDict(self):
|
||||
'''
|
||||
Beer XML file to dict
|
||||
:return: beer.xml file as dict
|
||||
'''
|
||||
try:
|
||||
import xmltodict
|
||||
with open(self.BEER_XML_FILE) as fd:
|
||||
doc = xmltodict.parse(fd.read())
|
||||
return doc
|
||||
except:
|
||||
self.api.notify(headline="Failed to load Beer.xml", message="Please check if you uploaded an beer.xml", type="danger")
|
||||
def getBoilTime(self, id):
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
return float(e.find('./RECIPE[%s]/BOIL_TIME' % (str(id))).text)
|
||||
|
||||
def getSteps(self, id):
|
||||
e = xml.etree.ElementTree.parse(self.BEER_XML_FILE).getroot()
|
||||
steps = []
|
||||
for e in e.findall('./RECIPE[%s]/MASH/MASH_STEPS/MASH_STEP' % (str(id))):
|
||||
steps.append({"name": e.find("NAME").text, "temp": float(e.find("STEP_TEMP").text), "timer": float(e.find("STEP_TIME").text)})
|
||||
|
||||
return steps
|
||||
|
||||
@cbpi.initalizer()
|
||||
def init(cbpi):
|
||||
|
||||
+1
-2
@@ -11,5 +11,4 @@ requests==2.11.0
|
||||
Werkzeug==0.11.10
|
||||
httplib2==0.9.2
|
||||
flask-classy==0.6.10
|
||||
GitPython==2.1.3
|
||||
|
||||
GitPython==2.1.3
|
||||
Reference in New Issue
Block a user