Exemple #1
0
    def load(self, id):


        steps = self.getSteps(id)
        boil_time_alerts = self.getBoilAlerts(id)
        name = self.getRecipeName(id)
        self.api.set_config_parameter("brew_name", name)
        boil_time = self.getBoilTime(id)
        mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)

        boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 100 if cbpi.get_config_parameter("unit", "C") == "C" else 212

        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()

        try:

            for row in steps:
                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 boiling step
            Step.insert(**{
                "name": "Boil",
                "type": boilstep_type,
                "config": {
                    "kettle": boil_kettle,
                    "temp": boil_temp,
                    "timer": boil_time,
                    ## Beer XML defines additions as the total time spent in boiling,
                    ## CBP defines it as time-until-alert

                    ## Also, The model supports five boil-time additions.
                    ## Set the rest to None to signal them being absent
                    "hop_1": boil_time - boil_time_alerts[0] if len(boil_time_alerts) >= 1 else None,
                    "hop_2": boil_time - boil_time_alerts[1] if len(boil_time_alerts) >= 2 else None,
                    "hop_3": boil_time - boil_time_alerts[2] if len(boil_time_alerts) >= 3 else None,
                    "hop_4": boil_time - boil_time_alerts[3] if len(boil_time_alerts) >= 4 else None,
                    "hop_5": boil_time - boil_time_alerts[4] if len(boil_time_alerts) >= 5 else None
                }
            })
            ## Add Whirlpool step
            Step.insert(**{"name": "Whirlpool", "type": "ChilStep", "config": {"timer": 15}})
            StepView().reset()
            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)

        return ('', 204)
Exemple #2
0
    def load(self, id):
        mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
        mashinstep_type = cbpi.get_config_parameter("step_mashin", "MashInStep")
        chilstep_type = cbpi.get_config_parameter("step_chil", "ChilStep")
        boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 100 if cbpi.get_config_parameter("unit", "C") == "C" else 212

        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()
        conn = None
        try:
            conn = sqlite3.connect(self.api.app.config['UPLOAD_FOLDER'] + '/kbh.db')
            c = conn.cursor()
            c.execute('SELECT EinmaischenTemp, Sudname FROM Sud WHERE ID = ?', (id,))
            row = c.fetchone()
            name = row[1]

            self.api.set_config_parameter("brew_name", name)
            Step.insert(**{"name": "MashIn", "type": mashinstep_type, "config": {"kettle": mash_kettle, "temp": row[0]}})
            ### add rest step
            for row in c.execute('SELECT * FROM Rasten WHERE SudID = ?', (id,)):
                Step.insert(**{"name": row[5], "type": mashstep_type, "config": {"kettle": mash_kettle, "temp": row[3], "timer": row[4]}})
            Step.insert(**{"name": "Chil", "type": chilstep_type, "config": {"timer": 15}})
            ## Add cooking step
            c.execute('SELECT max(Zeit) FROM Hopfengaben WHERE SudID = ?', (id,))
            row = c.fetchone()
            Step.insert(**{"name": "Boil", "type": boilstep_type, "config": {"kettle": boil_kettle, "temp": boil_temp, "timer": row[0]}})
            ## Add Whirlpool step
            Step.insert(**{"name": "Whirlpool", "type": chilstep_type, "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)
Exemple #3
0
    def load(self):

        try:
            data = request.json

            name = data.get("name", "No Name")

            self.api.set_config_parameter("brew_name", name)
            chilstep_type = cbpi.get_config_parameter("step_chil", "ChilStep")
            mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
            mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)

            boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
            boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
            boil_temp = 100 if cbpi.get_config_parameter("unit", "C") == "C" else 212

            # READ KBH DATABASE
            Step.delete_all()
            StepView().reset()


            for step in data.get("steps"):
                if step.get("type", None) == "MASH":
                    Step.insert(**{"name": step.get("name","Mash Step"), "type": mashstep_type, "config": {"kettle": mash_kettle, "temp": step.get("temp",0), "timer": step.get("timer",0)}})
                elif step.get("type", None) == "CHIL":
                    Step.insert(**{"name": step.get("name","Chil"), "type": chilstep_type, "config": {"timer": step.get("timer")}})
                elif step.get("type", None) == "BOIL":
                    Step.insert(**{"name": step.get("name", "Boil"), "type": boilstep_type, "config": {"kettle": boil_kettle, "timer": step.get("timer"), "temp": boil_temp}})
                else:
                    pass

            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", type="danger", message=str(e))
            m = str(e.message)
            return (str(e), 500)

        return ('', 204)
Exemple #4
0
    def load(self, id):

        name = self.getRecipeName(id)
        self.api.set_config_parameter("brew_name", name)
        steps = self.getSteps(id)
        first_wort_hops = self.getFirstWortHops(id)
        hops = self.getBoilAlerts(id)
        boil_time = self.getBoilTime(id)
        mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)
        mash_in_temp = self.getMashin(id)
        mash_out_temp = self.getMashout(id)

        boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 100 if cbpi.get_config_parameter("unit",
                                                     "C") == "C" else 212
        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()

        try:
            if 'modules.plugins.cbpi-SimpleUtilitySteps' in sys.modules:
                Step.insert(
                    **{
                        "name": "Clear Logs",
                        "type": "SimpleClearLogsStep",
                        "config": {}
                    })
            Step.insert(
                **{
                    "name": "Mash in",
                    "type": "MashInStep",
                    "config": {
                        "kettle": mash_kettle,
                        "temp": mash_in_temp
                    }
                })
            for row in steps:
                Step.insert(
                    **{
                        "name": row.get("name"),
                        "type": mashstep_type,
                        "config": {
                            "kettle": mash_kettle,
                            "temp": float(row.get("temp")),
                            "timer": row.get("timer")
                        }
                    })
            if 'modules.plugins.TelegramPushNotifications' in sys.modules:
                Step.insert(
                    **{
                        "name": "Iodine Test",
                        "type": "IodineStep",
                        "config": {
                            "kettle": mash_kettle,
                            "temp": 72,
                            "timer": 10
                        }
                    })
            Step.insert(
                **{
                    "name": "Mash out",
                    "type": "MashInStep",
                    "config": {
                        "kettle": mash_kettle,
                        "temp": mash_out_temp
                    }
                })
            if 'modules.plugins.cbpi-SimpleUtilitySteps' in sys.modules:
                if first_wort_hops is not "":
                    Step.insert(
                        **{
                            "name": "first wort hopping",
                            "type": "SimpleManualStep",
                            "config": {
                                "heading":
                                "first wort hopping",
                                "message":
                                "Adding these hops to the boiling kettle:\n" +
                                first_wort_hops + "\n press next button!",
                                "notifyType":
                                "success",
                                "proceed":
                                "Pause"
                            }
                        })
            Step.insert(**{
                "name": "ChilStep",
                "type": "ChilStep",
                "config": {
                    "timer": 45
                }
            })
            if 'modules.plugins.cbpi-SimpleUtilitySteps' in sys.modules:
                Step.insert(
                    **{
                        "name": "Measure Original Gravity",
                        "type": "SimpleManualStep",
                        "config": {
                            "heading": "Measure Original Gravity",
                            "message":
                            "what is the original gravity of the beer wort?",
                            "notifyType": "success",
                            "proceed": "Pause"
                        }
                    })
            ## Add boiling step
            Step.insert(
                **{
                    "name": "Boiling",
                    "type": boilstep_type,
                    "config": {
                        "kettle": boil_kettle,
                        "temp": boil_temp,
                        "temp_diff": 3,
                        "timer": boil_time,
                        ## The model supports seven boil-time additions.
                        ## Set the rest to None to signal them being absent
                        "hop_1": hops[0]["time"] if len(hops) >= 1 else None,
                        "hop_2": hops[1]["time"] if len(hops) >= 2 else None,
                        "hop_3": hops[2]["time"] if len(hops) >= 3 else None,
                        "hop_4": hops[3]["time"] if len(hops) >= 4 else None,
                        "hop_5": hops[4]["time"] if len(hops) >= 5 else None,
                        "hop_6": hops[5]["time"] if len(hops) >= 6 else None,
                        "hop_7": hops[6]["time"] if len(hops) >= 7 else None,
                        "hop_1_desc":
                        hops[0]["name"] if len(hops) >= 1 else None,
                        "hop_2_desc":
                        hops[1]["name"] if len(hops) >= 2 else None,
                        "hop_3_desc":
                        hops[2]["name"] if len(hops) >= 3 else None,
                        "hop_4_desc":
                        hops[3]["name"] if len(hops) >= 4 else None,
                        "hop_5_desc":
                        hops[4]["name"] if len(hops) >= 5 else None,
                        "hop_6_desc":
                        hops[5]["name"] if len(hops) >= 6 else None,
                        "hop_7_desc":
                        hops[6]["name"] if len(hops) >= 7 else None
                    }
                })
            if 'modules.plugins.cbpi-SimpleUtilitySteps' in sys.modules:
                Step.insert(
                    **{
                        "name": "Measure Original Gravity",
                        "type": "SimpleManualStep",
                        "config": {
                            "heading": "Measure Original Gravity",
                            "message":
                            "what is the original gravity of the beer wort?",
                            "notifyType": "success",
                            "proceed": "Pause"
                        }
                    })
            ## Add Whirlpool step
            Step.insert(**{
                "name": "Whirlpool",
                "type": "ChilStep",
                "config": {
                    "timer": 15
                }
            })
            if 'modules.plugins.cbpi-SimpleUtilitySteps' in sys.modules:
                Step.insert(
                    **{
                        "name": "Save Logs",
                        "type": "SimpleSaveLogsStep",
                        "config": {}
                    })
            StepView().reset()
            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)

        return ('', 204)
Exemple #5
0
    def load(self, id):

        if self.VerifyConfigurations() == False:
            return

        ImportBehavior.FLOWIN_AND_MASHIN_STEP_CREATION = cbpi.get_config_parameter(
            str(ImportBehavior.FLOWIN_AND_MASHIN_STEP_CREATION),
            str(FlowInAndMashInStepCreationEnum.DoNothing))

        steps = self.getSteps(id)
        boil_time_alerts = self.getBoilAlerts(id)
        name = self.getRecipeName(id)
        self.api.set_config_parameter("brew_name", name)
        boil_time = self.getBoilTime(id)
        mashInStep_type = cbpi.get_config_parameter("step_mashin",
                                                    MashStepTypes.MashinStep)
        mashStep_type = cbpi.get_config_parameter("step_mash",
                                                  MashStepTypes.MashStep)
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)

        boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 100 if cbpi.get_config_parameter("unit",
                                                     "C") == "C" else 212

        # totalWaterAmount = self.getTotalWater(id)
        spargeWaterAmount = self.getSpargeWaterVolume(id)
        spargeTemperature = self.getSpargeTemperature(id)

        # READ KBH DATABASE

        # Don't erase existing steps if configurated. It allow us to merge recipes steps with equipament/process steps.
        deleteSteps = cbpi.get_config_parameter(
            ImportBehavior.CLEAR_RECIPE_ON_IMPORT, YesNo.Yes)
        if deleteSteps == YesNo.Yes:
            Step.delete_all()

        StepView().reset()

        try:
            # MashSteps Only
            for row in steps:
                if row.get("type") == MashStepTypes.Flowmeter:
                    Step.insert(
                        **{
                            "name": row.get("name"),
                            "type": MashStepTypes.Flowmeter,
                            "config": {
                                "actorA": row.get("actorA"),
                                "sensor": row.get("sensor"),
                                "volume": float(row.get("volume")),
                                "resetFlowmeter": row.get("resetFlowmeter")
                            }
                        })
                elif row.get("type") == MashStepTypes.MashinStep:
                    Step.insert(
                        **{
                            "name": row.get("name"),
                            "type": mashInStep_type,
                            "config": {
                                "kettle": mash_kettle,
                                "temp": float(row.get("temp"))
                            }
                        })
                elif row.get("type") == MashStepTypes.MashStep:
                    Step.insert(
                        **{
                            "name": row.get("name"),
                            "type": mashStep_type,
                            "config": {
                                "kettle": mash_kettle,
                                "temp": float(row.get("temp")),
                                "timer": row.get("timer")
                            }
                        })
                # pass

            if self.PauseStepPluginIsInstalled() == True:
                Step.insert(
                    **{
                        "name": "Pause for Sparge",
                        "type": "PauseStep",
                        "config": {
                            "initialMessage":
                            u"Sparge with %s of water at %s " %
                            (spargeWaterAmount, spargeTemperature),
                            "titleOfInitialMessage":
                            u"Sparge Insctruction",
                            "timer":
                            10
                        }
                    })

            # Chil step need to be AFTER Boil!!!
            # Step.insert(**{"name": "ChilStep",
            #     "type": "ChilStep",
            #     "config": {
            #         "timer": 15}
            #         })

            ## Add boiling step
            Step.insert(
                **{
                    "name": "Boil",
                    "type": boilstep_type,
                    "config": {
                        "kettle":
                        boil_kettle,
                        "temp":
                        boil_temp,
                        "timer":
                        boil_time,
                        ## Beer XML defines additions as the total time spent in boiling,
                        ## CBP defines it as time-until-alert

                        ## Also, The model supports five boil-time additions.
                        ## Set the rest to None to signal them being absent
                        "hop_1":
                        boil_time - boil_time_alerts[0]
                        if len(boil_time_alerts) >= 1 else None,
                        "hop_2":
                        boil_time - boil_time_alerts[1]
                        if len(boil_time_alerts) >= 2 else None,
                        "hop_3":
                        boil_time - boil_time_alerts[2]
                        if len(boil_time_alerts) >= 3 else None,
                        "hop_4":
                        boil_time - boil_time_alerts[3]
                        if len(boil_time_alerts) >= 4 else None,
                        "hop_5":
                        boil_time - boil_time_alerts[4]
                        if len(boil_time_alerts) >= 5 else None
                    }
                })

            Step.insert(**{
                "name": "ChilStep",
                "type": "ChilStep",
                "config": {
                    "timer": 15
                }
            })

            ## Add Whirlpool step
            Step.insert(**{
                "name": "Whirlpool",
                "type": "ChilStep",
                "config": {
                    "timer": 15
                }
            })

            StepView().reset()

            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)

        return ('', 204)
Exemple #6
0
    def load(self, id):

        steps = self.getSteps(id)
        name = self.getRecipeName(id)
        self.api.set_config_parameter("brew_name", name)
        boil_time = self.getBoilTime(id)
        mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)

        boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 100 if cbpi.get_config_parameter("unit",
                                                     "C") == "C" else 212

        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()

        try:

            for row in steps:
                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
                }
            })
            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)

        return ('', 204)
Exemple #7
0
    def load(self, id):
        bm_recipe_creation = cbpi.get_config_parameter("bm_recipe_creation",
                                                       None)
        self.api.notify(headline="Braumeister Recipe Upload",
                        message="Activated: %s" % bm_recipe_creation)
        steps = self.getSteps(id)
        boil_time_alerts = self.getBoilAlerts(id)
        first_wort_alert = self.getFirstWortAlert(id)
        name = self.getRecipeName(id)
        self.api.set_config_parameter("brew_name", name)
        boil_time = self.getBoilTime(id)
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)
        boil_temp = 99 if cbpi.get_config_parameter("unit",
                                                    "C") == "C" else 210
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)

        if bm_recipe_creation == "NO" or bm_recipe_creation is None:
            mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
            boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
        else:
            mashinstep_type = "BM_MashInStep"
            mashstep_type = "BM_MashStep"
            mashoutstep_type = "BM_ManualStep"
            boilstep_type = "BM_BoilStep"
            firstwortstep_type = "BM_ManualStep"

        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()

        try:
            if bm_recipe_creation == "NO" or bm_recipe_creation is None:
                for row in steps:
                    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
                        }
                    })
                First_Wort_Flag = len(first_wort_alert)
                if First_Wort_Flag != 0:
                    Step.insert(
                        **{
                            "name": "First Wort Hopping",
                            "type": mashstep_type,
                            "config": {
                                "kettle": mash_kettle,
                                "temp": 0,
                                "timer": 0
                            }
                        })
            ## Add boiling step
                Step.insert(
                    **{
                        "name": "Boil",
                        "type": boilstep_type,
                        "config": {
                            "kettle":
                            boil_kettle,
                            "temp":
                            boil_temp,
                            "timer":
                            boil_time,
                            ## Beer XML defines additions as the total time spent in boiling,
                            ## CBP defines it as time-until-alert

                            ## Also, The model supports five boil-time additions.
                            ## Set the rest to None to signal them being absent
                            "first_wort_hop":
                            'Yes' if First_Wort_Flag != 0 else 'No',
                            "hop_1":
                            boil_time_alerts[0]
                            if len(boil_time_alerts) >= 1 else None,
                            "hop_2":
                            boil_time_alerts[1]
                            if len(boil_time_alerts) >= 2 else None,
                            "hop_3":
                            boil_time_alerts[2]
                            if len(boil_time_alerts) >= 3 else None,
                            "hop_4":
                            boil_time_alerts[3]
                            if len(boil_time_alerts) >= 4 else None,
                            "hop_5":
                            boil_time_alerts[4]
                            if len(boil_time_alerts) >= 5 else None
                        }
                    })
                ## Add Whirlpool step
                Step.insert(
                    **{
                        "name": "Whirlpool",
                        "type": "ChilStep",
                        "config": {
                            "timer": 15
                        }
                    })
                StepView().reset()
                self.api.emit("UPDATE_ALL_STEPS", Step.get_all())
                self.api.notify(headline="Recipe %s loaded successfully" %
                                name,
                                message="")
            else:
                MashIn_Flag = True
                for row in steps:
                    if MashIn_Flag == True and row.get("timer") == 0:
                        Step.insert(
                            **{
                                "name": row.get("name"),
                                "type": mashinstep_type,
                                "config": {
                                    "kettle": mash_kettle,
                                    "temp": float(row.get("temp")),
                                    "timer": row.get("timer")
                                }
                            })
                        MashIn_Flag = False
                    else:
                        Step.insert(
                            **{
                                "name": row.get("name"),
                                "type": mashstep_type,
                                "config": {
                                    "kettle": mash_kettle,
                                    "temp": float(row.get("temp")),
                                    "timer": row.get("timer")
                                }
                            })
                ## Add Step to remove malt pipe
                Step.insert(
                    **{
                        "name": "Remove Malt Pipe",
                        "type": mashoutstep_type,
                        "config": {
                            "heading": "MashOut Step Completed!",
                            "message":
                            "Please remove Malt Pipe and Sparge. Press Next to continue",
                            "notifyType": "info",
                            "proceed": "Pause",
                            "kettle": mash_kettle
                        }
                    })
                First_Wort_Flag = len(first_wort_alert)
                ## Add boiling step
                Step.insert(
                    **{
                        "name": "Boil",
                        "type": boilstep_type,
                        "config": {
                            "kettle":
                            boil_kettle,
                            "temp":
                            boil_temp,
                            "timer":
                            boil_time,
                            ## Beer XML defines additions as the total time spent in boiling,
                            ## CBP defines it as time-until-alert

                            ## Also, The model supports five boil-time additions.
                            ## Set the rest to None to signal them being absent
                            "first_wort_hop":
                            'Yes' if First_Wort_Flag != 0 else 'No',
                            "hop_1":
                            boil_time_alerts[0]
                            if len(boil_time_alerts) >= 1 else None,
                            "hop_2":
                            boil_time_alerts[1]
                            if len(boil_time_alerts) >= 2 else None,
                            "hop_3":
                            boil_time_alerts[2]
                            if len(boil_time_alerts) >= 3 else None,
                            "hop_4":
                            boil_time_alerts[3]
                            if len(boil_time_alerts) >= 4 else None,
                            "hop_5":
                            boil_time_alerts[4]
                            if len(boil_time_alerts) >= 5 else None
                        }
                    })
                ## Add Whirlpool step
                Step.insert(
                    **{
                        "name": "Whirlpool",
                        "type": "ChilStep",
                        "config": {
                            "timer": 15
                        }
                    })
                StepView().reset()
                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)

        return ('', 204)
Exemple #8
0
    def load(self, id):
        bm_recipe_creation = cbpi.get_config_parameter("bm_recipe_creation",
                                                       None)
        self.api.notify(headline="Braumeister Recipe Upload",
                        message="Activated: %s" % bm_recipe_creation)

        if bm_recipe_creation == "YES" and KBH_VERSION == 2:
            mashstep_type = "BM_MashStep"
            mashinstep_type = "BM_MashInStep"
            mashoutstep_type = "BM_ManualStep"
            boilstep_type = "BM_BoilStep"
            firstwortstep_type = "BM_ManualStep"
            boil_temp = 99 if cbpi.get_config_parameter("unit",
                                                        "C") == "C" else 210

        else:
            mashstep_type = cbpi.get_config_parameter("step_mash", "MashStep")
            mashinstep_type = cbpi.get_config_parameter(
                "step_mashin", "MashInStep")
            boilstep_type = cbpi.get_config_parameter("step_boil", "BoilStep")
            boil_temp = 100 if cbpi.get_config_parameter("unit",
                                                         "C") == "C" else 212

        chilstep_type = cbpi.get_config_parameter("step_chil", "ChilStep")
        mash_kettle = cbpi.get_config_parameter("step_mash_kettle", None)
        boil_kettle = cbpi.get_config_parameter("step_boil_kettle", None)

        # READ KBH DATABASE
        Step.delete_all()
        StepView().reset()
        conn = None
        try:
            conn = sqlite3.connect(self.api.app.config['UPLOAD_FOLDER'] +
                                   '/kbh.db')
            c = conn.cursor()
            if KBH_VERSION == 1:  # kbh database v1
                c.execute(
                    'SELECT EinmaischenTemp, Sudname FROM Sud WHERE ID = ?',
                    (id, ))
                row = c.fetchone()
                name = row[1]
                self.api.set_config_parameter("brew_name", name)
                Step.insert(
                    **{
                        "name": "MashIn",
                        "type": mashinstep_type,
                        "config": {
                            "kettle": mash_kettle,
                            "temp": row[0]
                        }
                    })

                for row in c.execute('SELECT * FROM Rasten WHERE SudID = ?',
                                     (id, )):
                    Step.insert(
                        **{
                            "name": row[5],
                            "type": mashstep_type,
                            "config": {
                                "kettle": mash_kettle,
                                "temp": row[3],
                                "timer": row[4]
                            }
                        })
                Step.insert(**{
                    "name": "Chil",
                    "type": chilstep_type,
                    "config": {
                        "timer": 15
                    }
                })
                ## Add cooking step
                c.execute('SELECT max(Zeit) FROM Hopfengaben WHERE SudID = ?',
                          (id, ))
                row = c.fetchone()
                Step.insert(
                    **{
                        "name": "Boil",
                        "type": boilstep_type,
                        "config": {
                            "kettle": boil_kettle,
                            "temp": boil_temp,
                            "timer": row[0]
                        }
                    })
            else:  # KBH Version 2 databse
                c.execute('SELECT Sudname FROM Sud WHERE ID = ?', (id, ))
                row = c.fetchone()
                name = row[0]
                self.api.set_config_parameter("brew_name", name)
                c.execute(
                    'SELECT Temp FROM Rasten WHERE Typ = 0 AND SudID = ?',
                    (id, ))
                row = c.fetchone()
                Step.insert(
                    **{
                        "name": "MashIn",
                        "type": mashinstep_type,
                        "config": {
                            "kettle": mash_kettle,
                            "temp": row[0]
                        }
                    })
                for row in c.execute(
                        'SELECT Name, Temp, Dauer FROM Rasten WHERE Typ <> 0 AND SudID = ?',
                    (id, )):
                    Step.insert(
                        **{
                            "name": row[0],
                            "type": mashstep_type,
                            "config": {
                                "kettle": mash_kettle,
                                "temp": row[1],
                                "timer": row[2]
                            }
                        })
                ## Add Step to remove malt pipe and eventually first wort hop step if BM recipe usage is defined
                if bm_recipe_creation == "YES":
                    ## Add Step to remove malt pipe
                    Step.insert(
                        **{
                            "name": "Remove Malt Pipe",
                            "type": mashoutstep_type,
                            "config": {
                                "heading": "MashOut Step Completed!",
                                "message":
                                "Please remove Malt Pipe and Sparge. Press Next to continue",
                                "notifyType": "info",
                                "proceed": "Pause",
                                "kettle": mash_kettle
                            }
                        })
                ## Check if first wort step needs to be added
                first_wort_alert = self.getFirstWortAlert(id)
                ## Add boil step
                boil_time_alerts = self.getBoilAlerts(id)
                c.execute('SELECT Kochdauer FROM Sud WHERE ID = ?', (id, ))
                row = c.fetchone()
                ## Add boiling step
                Step.insert(
                    **{
                        "name": "Boil",
                        "type": boilstep_type,
                        "config": {
                            "kettle":
                            boil_kettle,
                            "temp":
                            boil_temp,
                            "timer":
                            row[0],
                            ## Beer XML defines additions as the total time spent in boiling,
                            ## CBP defines it as time-until-alert

                            ## Also, The model supports five boil-time additions.
                            ## Set the rest to None to signal them being absent
                            "first_wort_hop":
                            'Yes' if first_wort_alert == True else 'No',
                            "hop_1":
                            boil_time_alerts[0]
                            if len(boil_time_alerts) >= 1 else None,
                            "hop_2":
                            boil_time_alerts[1]
                            if len(boil_time_alerts) >= 2 else None,
                            "hop_3":
                            boil_time_alerts[2]
                            if len(boil_time_alerts) >= 3 else None,
                            "hop_4":
                            boil_time_alerts[3]
                            if len(boil_time_alerts) >= 4 else None,
                            "hop_5":
                            boil_time_alerts[4]
                            if len(boil_time_alerts) >= 5 else None
                        }
                    })
            ## Add Whirlpool step
            Step.insert(
                **{
                    "name": "Whirlpool",
                    "type": chilstep_type,
                    "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)