From 4e234f475326bc2dbeb7cb85d5dab00a7e77ef25 Mon Sep 17 00:00:00 2001 From: lopelex Date: Sat, 5 Nov 2022 12:57:44 +0100 Subject: [PATCH] add hop text --- cbpi/controller/upload_controller.py | 146 +++++++++++++++++---------- 1 file changed, 92 insertions(+), 54 deletions(-) diff --git a/cbpi/controller/upload_controller.py b/cbpi/controller/upload_controller.py index 7fa0cd3..e2828a2 100644 --- a/cbpi/controller/upload_controller.py +++ b/cbpi/controller/upload_controller.py @@ -203,11 +203,11 @@ class UploadController: hops.remove(whirl) # 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() 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() FirstWort = self.getFirstWort(FW_Hops,"kbh") except: @@ -297,14 +297,21 @@ class UploadController: "Sensor": self.boilkettle.sensor, "Temp": int(self.BoilTemp), "Timer": BoilTime, - "First_Wort": FirstWort, + "First_Wort": FirstWort[0], + "First_Wort_text": FirstWort[1], "LidAlert": "Yes", - "Hop_1": Hops[0], - "Hop_2": Hops[1], - "Hop_3": Hops[2], - "Hop_4": Hops[3], - "Hop_5": Hops[4], - "Hop_6": Hops[5] + "Hop_1": Hops[0][0], + "Hop_1_text": Hops[0][1], + "Hop_2": Hops[1][0], + "Hop_2_text": Hops[1][1], + "Hop_3": Hops[2][0], + "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": "I", @@ -363,11 +370,12 @@ class UploadController: if e["Hopfen_{}_Kochzeit".format(idx)].isnumeric(): if boil_time is not e["Hopfen_{}_Kochzeit".format(idx)].isnumeric(): alert = float(e["Hopfen_{}_Kochzeit".format(idx)]) - elif e["Hopfen_{}_Kochzeit".format(idx)] == "Whirlpool": - alert = float(1) + elif e["Hopfen_{}_Kochzeit".format(idx)] == "Whirlpool" or float(e["Hopfen_{}_Kochzeit".format(idx)]) < 0: + alert = float(0) + hops_name = hops_name + ' whirlpool' else: - self.api.notify(headline="No Number at Hoptime", message="Please change json-File at Hopfen_{}_Kochzeit".format(idx), type="danger") - alert = float(1) + self.cbpi.notify("No Number at Hoptime", "Please change json-File at Hopfen_{}_Kochzeit".format(idx), NotificationType.ERROR) + alert = float(0) 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)]) if e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)].isnumeric(): alert = float(e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)]) - elif e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)] == "Whirlpool": - alert = float(1) + elif e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)] == "Whirlpool" or float(e["WeitereZutat_Wuerze_{}_Kochzeit".format(idx)]) < 0: + alert = float(0) + miscs_name = miscs_name + ' whirlpool' else: 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}) @@ -519,14 +528,21 @@ class UploadController: "Sensor": sensor, "Temp": step_temp, "Timer": step_time, - "First_Wort": FirstWort, + "First_Wort": FirstWort[0], + "First_Wort_text": FirstWort[1], "LidAlert": LidAlert, - "Hop_1": Hops[0], - "Hop_2": Hops[1], - "Hop_3": Hops[2], - "Hop_4": Hops[3], - "Hop_5": Hops[4], - "Hop_6": Hops[5] + "Hop_1": Hops[0][0], + "Hop_1_text": Hops[0][1], + "Hop_2": Hops[1][0], + "Hop_2_text": Hops[1][1], + "Hop_3": Hops[2][0], + "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": "I", @@ -665,14 +681,21 @@ class UploadController: "Sensor": sensor, "Temp": step_temp, "Timer": step_time, - "First_Wort": FirstWort, + "First_Wort": FirstWort[0], + "First_Wort_text": FirstWort[1], "LidAlert": LidAlert, - "Hop_1": Hops[0], - "Hop_2": Hops[1], - "Hop_3": Hops[2], - "Hop_4": Hops[3], - "Hop_5": Hops[4], - "Hop_6": Hops[5] + "Hop_1": Hops[0][0], + "Hop_1_text": Hops[0][1], + "Hop_2": Hops[1][0], + "Hop_2_text": Hops[1][1], + "Hop_3": Hops[2][0], + "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": "I", @@ -867,14 +890,21 @@ class UploadController: "Sensor": sensor, "Temp": step_temp, "Timer": step_time, - "First_Wort": FirstWort, + "First_Wort": FirstWort[0], + "First_Wort_text": FirstWort[1], "LidAlert": LidAlert, - "Hop_1": Hops[0], - "Hop_2": Hops[1], - "Hop_3": Hops[2], - "Hop_4": Hops[3], - "Hop_5": Hops[4], - "Hop_6": Hops[5] + "Hop_1": Hops[0][0], + "Hop_1_text": Hops[0][1], + "Hop_2": Hops[1][0], + "Hop_2_text": Hops[1][1], + "Hop_3": Hops[2][0], + "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": "I", @@ -897,48 +927,51 @@ class UploadController: ## Hops which are not used in the boil step should not cause alerts if use != 'Aroma' and use != 'Boil': continue - alerts.append(float(hop.find('TIME').text)) + alerts.append([float(hop.find('TIME').text), hop.find('NAME').text]) elif recipe_type == "bf": use = hop['use'] if use != 'Aroma' and use != 'Boil': continue - alerts.append(float(hop['time'])) + alerts.append([float(hop['time']), hop['name']]) ## TODO: Testing elif recipe_type == "kbh": - alerts.append(float(hop[0])) + alerts.append([float(hop[0]), hop[1]]) 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 if miscs is not None: for misc in miscs: 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": use = misc['use'] if use != 'Aroma' and use != 'Boil': continue - alerts.append(float(misc['time'])) + alerts.append([float(misc['time']), misc['name']]) ## TODO: Testing elif recipe_type == "kbh": - alerts.append(float(misc[0])) + alerts.append([float(misc[0]), misc[1]]) elif recipe_type == "json": - alerts.append(float(misc['time'])) - ## Dedupe and order the additions by their time, to prevent multiple alerts at the same time - alerts = sorted(list(set(alerts))) + alerts.append([float(misc['time']), misc['name']]) + ## Dedupe and order the additions by their time ## CBP should have these additions in reverse - alerts.reverse() - hop_alerts = [] + alerts = sorted(alerts, key=lambda x:x[0], reverse=True) + hop_alerts = [[None, None],[None, None],[None, None],[None, None],[None, None],[None, None]] for i in range(0,6): try: - hop_alerts.append(str(int(alerts[i]))) + if float(alerts[i][0]) > -1: + hop_alerts[i] = alerts[i] except: - hop_alerts.append(None) + pass return hop_alerts def getFirstWort(self, hops, recipe_type): alert = "No" + names = [] if recipe_type == "kbh": if len(hops) != 0: alert = "Yes" + for hop in hops: + names.append(hop[1]) elif recipe_type == "xml": for hop in hops: use = hop.find('USE').text @@ -946,14 +979,19 @@ class UploadController: if use != 'First Wort': continue alert = "Yes" + names.append(hop.find('NAME').text) elif recipe_type == "bf": for hop in hops: if hop['use'] == "First Wort": alert="Yes" + names.append(hop['name']) ## TODO: Testing elif recipe_type == "json": - for hop in hops: - alert="Yes" - return alert + if len(hops) != 0: + alert = "Yes" + for hop in hops: + names.append(hop['name']) + + return [alert, " and ".join(names)] async def create_Whirlpool_Cooldown(self, time : str = "15"): # Add Waitstep as Whirlpool