Merge pull request #75 from lopelex/development

add hop text
This commit is contained in:
Alexander Vollkopf 2022-11-19 12:21:04 +01:00 committed by GitHub
commit a9f3bef7c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -203,11 +203,11 @@ class UploadController:
hops.remove(whirl) hops.remove(whirl)
# get the misc addition times # get the misc addition times
c.execute('SELECT Zugabedauer FROM WeitereZutatenGaben WHERE Zeitpunkt = 1 AND SudID = ?', (Recipe_ID,)) c.execute('SELECT Zugabedauer, Name FROM WeitereZutatenGaben WHERE Zeitpunkt = 1 AND SudID = ?', (Recipe_ID,))
miscs = c.fetchall() miscs = c.fetchall()
try: try:
c.execute('SELECT Zeit FROM Hopfengaben WHERE Vorderwuerze = 1 AND SudID = ?', (Recipe_ID,)) c.execute('SELECT Zeit, Name FROM Hopfengaben WHERE Vorderwuerze = 1 AND SudID = ?', (Recipe_ID,))
FW_Hops = c.fetchall() FW_Hops = c.fetchall()
FirstWort = self.getFirstWort(FW_Hops,"kbh") FirstWort = self.getFirstWort(FW_Hops,"kbh")
except: except:
@ -297,14 +297,21 @@ class UploadController:
"Sensor": self.boilkettle.sensor, "Sensor": self.boilkettle.sensor,
"Temp": int(self.BoilTemp), "Temp": int(self.BoilTemp),
"Timer": BoilTime, "Timer": BoilTime,
"First_Wort": FirstWort, "First_Wort": FirstWort[0],
"First_Wort_text": FirstWort[1],
"LidAlert": "Yes", "LidAlert": "Yes",
"Hop_1": Hops[0], "Hop_1": Hops[0][0],
"Hop_2": Hops[1], "Hop_1_text": Hops[0][1],
"Hop_3": Hops[2], "Hop_2": Hops[1][0],
"Hop_4": Hops[3], "Hop_2_text": Hops[1][1],
"Hop_5": Hops[4], "Hop_3": Hops[2][0],
"Hop_6": Hops[5] "Hop_3_text": Hops[2][1],
"Hop_4": Hops[3][0],
"Hop_4_text": Hops[3][1],
"Hop_5": Hops[4][0],
"Hop_5_text": Hops[4][1],
"Hop_6": Hops[5][0],
"Hop_6_text": Hops[5][1]
}, },
"status_text": "", "status_text": "",
"status": "I", "status": "I",
@ -363,11 +370,12 @@ class UploadController:
if e["Hopfen_{}_Kochzeit".format(idx)].isnumeric(): if e["Hopfen_{}_Kochzeit".format(idx)].isnumeric():
if boil_time is not e["Hopfen_{}_Kochzeit".format(idx)].isnumeric(): if boil_time is not e["Hopfen_{}_Kochzeit".format(idx)].isnumeric():
alert = float(e["Hopfen_{}_Kochzeit".format(idx)]) alert = float(e["Hopfen_{}_Kochzeit".format(idx)])
elif e["Hopfen_{}_Kochzeit".format(idx)] == "Whirlpool": elif e["Hopfen_{}_Kochzeit".format(idx)] == "Whirlpool" or float(e["Hopfen_{}_Kochzeit".format(idx)]) < 0:
alert = float(1) alert = float(0)
hops_name = hops_name + ' whirlpool'
else: else:
self.api.notify(headline="No Number at Hoptime", message="Please change json-File at Hopfen_{}_Kochzeit".format(idx), type="danger") self.cbpi.notify("No Number at Hoptime", "Please change json-File at Hopfen_{}_Kochzeit".format(idx), NotificationType.ERROR)
alert = float(1) alert = float(0)
hops.append({"name":hops_name,"time":alert}) hops.append({"name":hops_name,"time":alert})
@ -385,11 +393,12 @@ class UploadController:
miscs_name = "%s%s %s" % (e["WeitereZutat_Wuerze_{}_Menge".format(idx)],e["WeitereZutat_Wuerze_{}_Einheit".format(idx)],e["WeitereZutat_Wuerze_{}_Name".format(idx)]) miscs_name = "%s%s %s" % (e["WeitereZutat_Wuerze_{}_Menge".format(idx)],e["WeitereZutat_Wuerze_{}_Einheit".format(idx)],e["WeitereZutat_Wuerze_{}_Name".format(idx)])
if e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)].isnumeric(): if e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)].isnumeric():
alert = float(e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)]) alert = float(e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)])
elif e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)] == "Whirlpool": elif e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)] == "Whirlpool" or float(e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)]) < 0:
alert = float(1) alert = float(0)
miscs_name = miscs_name + ' whirlpool'
else: else:
self.api.notify(headline="No Number at Hoptime", message="Please change json-File at WeitereZutat_Wuerze_{}_Kochzeit".format(idx), type="danger") self.api.notify(headline="No Number at Hoptime", message="Please change json-File at WeitereZutat_Wuerze_{}_Kochzeit".format(idx), type="danger")
alert = float(1) alert = float(0)
miscs.append({"name":miscs_name,"time":alert}) miscs.append({"name":miscs_name,"time":alert})
@ -519,14 +528,21 @@ class UploadController:
"Sensor": sensor, "Sensor": sensor,
"Temp": step_temp, "Temp": step_temp,
"Timer": step_time, "Timer": step_time,
"First_Wort": FirstWort, "First_Wort": FirstWort[0],
"First_Wort_text": FirstWort[1],
"LidAlert": LidAlert, "LidAlert": LidAlert,
"Hop_1": Hops[0], "Hop_1": Hops[0][0],
"Hop_2": Hops[1], "Hop_1_text": Hops[0][1],
"Hop_3": Hops[2], "Hop_2": Hops[1][0],
"Hop_4": Hops[3], "Hop_2_text": Hops[1][1],
"Hop_5": Hops[4], "Hop_3": Hops[2][0],
"Hop_6": Hops[5] "Hop_3_text": Hops[2][1],
"Hop_4": Hops[3][0],
"Hop_4_text": Hops[3][1],
"Hop_5": Hops[4][0],
"Hop_5_text": Hops[4][1],
"Hop_6": Hops[5][0],
"Hop_6_text": Hops[5][1]
}, },
"status_text": "", "status_text": "",
"status": "I", "status": "I",
@ -665,14 +681,21 @@ class UploadController:
"Sensor": sensor, "Sensor": sensor,
"Temp": step_temp, "Temp": step_temp,
"Timer": step_time, "Timer": step_time,
"First_Wort": FirstWort, "First_Wort": FirstWort[0],
"First_Wort_text": FirstWort[1],
"LidAlert": LidAlert, "LidAlert": LidAlert,
"Hop_1": Hops[0], "Hop_1": Hops[0][0],
"Hop_2": Hops[1], "Hop_1_text": Hops[0][1],
"Hop_3": Hops[2], "Hop_2": Hops[1][0],
"Hop_4": Hops[3], "Hop_2_text": Hops[1][1],
"Hop_5": Hops[4], "Hop_3": Hops[2][0],
"Hop_6": Hops[5] "Hop_3_text": Hops[2][1],
"Hop_4": Hops[3][0],
"Hop_4_text": Hops[3][1],
"Hop_5": Hops[4][0],
"Hop_5_text": Hops[4][1],
"Hop_6": Hops[5][0],
"Hop_6_text": Hops[5][1]
}, },
"status_text": "", "status_text": "",
"status": "I", "status": "I",
@ -867,14 +890,21 @@ class UploadController:
"Sensor": sensor, "Sensor": sensor,
"Temp": step_temp, "Temp": step_temp,
"Timer": step_time, "Timer": step_time,
"First_Wort": FirstWort, "First_Wort": FirstWort[0],
"First_Wort_text": FirstWort[1],
"LidAlert": LidAlert, "LidAlert": LidAlert,
"Hop_1": Hops[0], "Hop_1": Hops[0][0],
"Hop_2": Hops[1], "Hop_1_text": Hops[0][1],
"Hop_3": Hops[2], "Hop_2": Hops[1][0],
"Hop_4": Hops[3], "Hop_2_text": Hops[1][1],
"Hop_5": Hops[4], "Hop_3": Hops[2][0],
"Hop_6": Hops[5] "Hop_3_text": Hops[2][1],
"Hop_4": Hops[3][0],
"Hop_4_text": Hops[3][1],
"Hop_5": Hops[4][0],
"Hop_5_text": Hops[4][1],
"Hop_6": Hops[5][0],
"Hop_6_text": Hops[5][1]
}, },
"status_text": "", "status_text": "",
"status": "I", "status": "I",
@ -897,48 +927,51 @@ class UploadController:
## Hops which are not used in the boil step should not cause alerts ## Hops which are not used in the boil step should not cause alerts
if use != 'Aroma' and use != 'Boil': if use != 'Aroma' and use != 'Boil':
continue continue
alerts.append(float(hop.find('TIME').text)) alerts.append([float(hop.find('TIME').text), hop.find('NAME').text])
elif recipe_type == "bf": elif recipe_type == "bf":
use = hop['use'] use = hop['use']
if use != 'Aroma' and use != 'Boil': if use != 'Aroma' and use != 'Boil':
continue continue
alerts.append(float(hop['time'])) alerts.append([float(hop['time']), hop['name']]) ## TODO: Testing
elif recipe_type == "kbh": elif recipe_type == "kbh":
alerts.append(float(hop[0])) alerts.append([float(hop[0]), hop[1]])
elif recipe_type == "json": elif recipe_type == "json":
alerts.append(float(hop['time'])) alerts.append([float(hop['time']), hop['name']])
## There might also be miscelaneous additions during boild time ## There might also be miscelaneous additions during boild time
if miscs is not None: if miscs is not None:
for misc in miscs: for misc in miscs:
if recipe_type == "xml": if recipe_type == "xml":
alerts.append(float(misc.find('TIME').text)) alerts.append([float(misc.find('TIME').text), misc.find('NAME').text])
elif recipe_type == "bf": elif recipe_type == "bf":
use = misc['use'] use = misc['use']
if use != 'Aroma' and use != 'Boil': if use != 'Aroma' and use != 'Boil':
continue continue
alerts.append(float(misc['time'])) alerts.append([float(misc['time']), misc['name']]) ## TODO: Testing
elif recipe_type == "kbh": elif recipe_type == "kbh":
alerts.append(float(misc[0])) alerts.append([float(misc[0]), misc[1]])
elif recipe_type == "json": elif recipe_type == "json":
alerts.append(float(misc['time'])) alerts.append([float(misc['time']), misc['name']])
## Dedupe and order the additions by their time, to prevent multiple alerts at the same time ## Dedupe and order the additions by their time
alerts = sorted(list(set(alerts)))
## CBP should have these additions in reverse ## CBP should have these additions in reverse
alerts.reverse() alerts = sorted(alerts, key=lambda x:x[0], reverse=True)
hop_alerts = [] hop_alerts = [[None, None],[None, None],[None, None],[None, None],[None, None],[None, None]]
for i in range(0,6): for i in range(0,6):
try: try:
hop_alerts.append(str(int(alerts[i]))) if float(alerts[i][0]) > -1:
hop_alerts[i] = alerts[i]
except: except:
hop_alerts.append(None) pass
return hop_alerts return hop_alerts
def getFirstWort(self, hops, recipe_type): def getFirstWort(self, hops, recipe_type):
alert = "No" alert = "No"
names = []
if recipe_type == "kbh": if recipe_type == "kbh":
if len(hops) != 0: if len(hops) != 0:
alert = "Yes" alert = "Yes"
for hop in hops:
names.append(hop[1])
elif recipe_type == "xml": elif recipe_type == "xml":
for hop in hops: for hop in hops:
use = hop.find('USE').text use = hop.find('USE').text
@ -946,14 +979,19 @@ class UploadController:
if use != 'First Wort': if use != 'First Wort':
continue continue
alert = "Yes" alert = "Yes"
names.append(hop.find('NAME').text)
elif recipe_type == "bf": elif recipe_type == "bf":
for hop in hops: for hop in hops:
if hop['use'] == "First Wort": if hop['use'] == "First Wort":
alert="Yes" alert="Yes"
names.append(hop['name']) ## TODO: Testing
elif recipe_type == "json": elif recipe_type == "json":
for hop in hops: if len(hops) != 0:
alert="Yes" alert = "Yes"
return alert for hop in hops:
names.append(hop['name'])
return [alert, " and ".join(names)]
async def create_Whirlpool_Cooldown(self, time : str = "15"): async def create_Whirlpool_Cooldown(self, time : str = "15"):
# Add Waitstep as Whirlpool # Add Waitstep as Whirlpool