예제 #1
0
def testRecipeCheck():
    ctrl1 = createCtrl()
    #ctrl1 = ctrl.controllerList()
    #ctrl1.load()

    print len(ctrl1)
    for key, c in ctrl1.items():
        print key

    here = os.getcwd()
    print here
    try:
        js = recipeReader.jsonStages('src/ctrl/tests/json_data', ctrl1)
    except:
        try:
            js = recipeReader.jsonStages('ctrl/tests/json_data', ctrl1)
        except:
            try:
                js = recipeReader.jsonStages('tests/json_data', ctrl1)
            except:
                js = recipeReader.jsonStages('json_data', ctrl1)
    #js = ctrl.jsonStages(data, ctrl1)
    stages = js.getStages()
    assert len(stages) > 0
    print "========================"
    pprint(stages)
    print "========================"
    assert ctrl.checkers.checkRecipe(ctrl1, stages, True)
    name = js.getRecipeName()
    print 'Name:', name
    assert len(name) > 0
예제 #2
0
def test_getStages():
    """
    Try different input format for stages and read them back.
       json from recipeReader
       json string
       dict
    """
    r1 = recipeReader.jsonStages(simpleStages(), simpleCtrl())
    a1 = stages2beer.s2b(simpleCtrl(), r1.getStages())
    stages1 = a1.getStages()
    assert isinstance(stages1, dict)
    assert '1stage' in stages1
    assert 'name' not in stages1

    a2 = stages2beer.s2b(simpleCtrl(), simpleDict())
    stages2 = a2.getStages()
    assert isinstance(stages2, dict)
    assert '1 stage' in stages2
    assert 'name' not in stages2

    a4 = stages2beer.s2b(simpleCtrl(), timerDict())
    stages4 = a4.getStages()
    assert isinstance(stages4, dict)
    assert '1 stage' in stages4
    assert 'name' not in stages4
    print myname(), "OK"
예제 #3
0
def test_badRecipeRead():
    js = jsonStages(badRecipe(), ctrlDummyList())
    assert js.getRecipeName() == "IPA"
    stages = js.getStages()
    assert stages["4step"] is not None
    oneStage = stages["4step"]
    assert oneStage is not None
    oneAction = oneStage["thingimajing"]
    assert oneAction is not None
    assert oneAction['active']
    assert oneAction['targetValue'] == 1.0
    assert not js.isValid()

    print "ok"
예제 #4
0
def test_m2ReadCtrlDict():
    js = jsonStages(m2Recipe(), ctrlDummyDict())
    assert js.getRecipeName() == "IPA"
    stages = js.getStages()
    assert stages["4step"] is not None
    oneStage = stages["4step"]
    assert oneStage is not None
    oneAction = oneStage["wortPump"]
    assert oneAction is not None
    assert oneAction['active']
    assert oneAction['targetValue'] == 1.0
    assert js.isValid()

    print "ok"
예제 #5
0
def testReadStages():
    ctrl1 = createCtrl()
    here = os.getcwd()
    print here
    try:
        js = recipeReader.jsonStages("src/ctrl/tests/json_data", ctrl1)
    except:
        try:
            js = recipeReader.jsonStages("ctrl/tests/json_data", ctrl1)
        except:
            try:
                js = recipeReader.jsonStages("tests/json_data", ctrl1)
            except:
                js = recipeReader.jsonStages("json_data", ctrl1)
    # js = ctrl.jsonStages(data, ctrl1)
    stages = js.getStages()
    assert len(stages) > 0
    pprint(stages)
    ctrlCount = len(ctrl1)
    print ctrlCount
    for s_key, s_val in stages.items():
        print s_key
        assert ctrlCount == len(s_val)
예제 #6
0
def test_wortpumptest():
    cp = os.path.dirname(__file__)
    print cp
    rp = cp + "/../../recipe/wort_pump_test"
    print rp
    js = jsonStages(rp, ctrlDummyList())
    print js.getRecipeName()
    print js.getStages()
    assert js.getRecipeName() == "wort_pump_test"
    stages = js.getStages()
    assert stages["01"] is not None
    oneStage = stages["01"]
    assert oneStage is not None
    oneAction = oneStage["wortPump"]
    assert oneAction is not None
    assert oneAction['active']
    assert js.isValid()
    print "ok"
예제 #7
0
    def doCommand(self):
        print "doCommand"
        runStatus = request.forms.get('runStatus')

        if runStatus == 'stop':
            self.s2b.stop()
            self.dl.stop()
            self.s2b.unpause()
        elif runStatus == 'run':
            print "starting"
            print self.s2b.isAlive()
            if not self.s2b.isAlive():
                self.runningRecipeName = self.selectedRecipeName
                self.s2b = stages2beer.s2b(self.controllers, self.stages)
                self.dl = ctrl.datalogger(self.controllers)
                self.s2b.start()
                self.dl.start()

        pauseState = request.forms.get('pauseState')
        if pauseState == "True":
            self.s2b.pause()
        else:
            self.s2b.unpause()

        skipState = request.forms.get('skipState')
        if skipState == "True":
            self.s2b.skip()

        preHeatState = request.forms.get('preHeatState')
        if preHeatState == "True":
            if not self.s2b.isAlive():
                preHeat = {"name": "heat_only", "recipe":
                           {"01": {"waterHeater": 170}}}
                js = recipeReader.jsonStages(preHeat, self.controllers)
                self.s2b = stages2beer.s2b(self.controllers, js.getStages())
                self.s2b.start()
            else:
                print "Already running, can not switch to preheat"

        return(self.commandPage())
예제 #8
0
        elif opt in ('-v', '--verbose'):
            optret['verbose'] = True
    return(optret)

if __name__ == "__main__":
    options = getOptions()
    controllers = ctrl.setupControllers(False, True, True)
    if options['inputfile'] is None:
        inf = sys.stdin
    else:
        try:
            inf = open(options['inputfile'], 'r')
        except:
            print "Can not open inputfile"
            sys.exit(1)
    if options['outputfile'] is None:
        outf = sys.stdout
    else:
        try:
            outf = open(options['outputfile'], 'w')
        except:
            print "Can not open outputfile", options['outputfile']
            sys.exit(1)
    jsonStr = inf.read()
    inf.close()
    jsonObj = recipeReader.jsonStages(jsonStr, controllers)
    stagesStr = jsonObj.getStages()
    json.dump(stagesStr, outf, sort_keys=True,
                           indent=2, separators=(',', ': '))
    outf.close()
예제 #9
0
def test_check():
    r = recipeReader.jsonStages(simpleStages(), simpleCtrl())
    a = stages2beer.s2b(simpleCtrl(), r.getStages())
    assert a.check()
    print myname(), "OK"
예제 #10
0
    if HWcheck:
        simulation = (simulation or (not HWcheck))
    else:
        simulation = False
    controllers = ctrl.setupControllers(verbose, simulation, permissive)

    if HWcheck:
        if controllers.HWOK():
            logging.info('USB devices connected')
        else:
            logging.info('ERROR: Missing USB devices, exiting')
            sys.exit(1)

    # Read one of the recipe files
    if recipeFile != "":
        j = recipeReader.jsonStages(recipeFile, controllers)
        if not j.isValid():
            logging.error("Error: bad json recipe")
        else:
            recipeName = j.getRecipeName()
            stages = j.getStages()
    elif bsmxFile != "":
        b = recipeReader.bsmxStages(bsmxFile, controllers)
        if not b.isValid():
            logging.error("Error: bad bsmx recipe")
        else:
            recipeName = b.getRecipeName()
            stages = b.getStages()
    else:
        recipeName = ""
        stages = {}