if IsInBrew() == 'InBrew':
# first lets work out where we are...
thisBrew = getCurrentBrewID()
latestStage = getCurrentStage(thisBrew)
elapsedtime = now - latestStage[1]
hours = divmod(elapsedtime.total_seconds(),3600)
minutes = divmod(hours[1], 60)
totalMinutes = (hours * 60) + minutes
#addDebug('%d hours, %d minutes' % (hours[0], minutes[0]))
if latestStage[0] == 'Fill HLT':
# we can't do anything until HLT is full
addDebug('Current Temp:' + str(getHLTTemperature()))
elif latestStage[0] == 'Boil HLT':
# we are now boiling up so check temp against our max value
addDebug('In Boil HLT %s' % getHLTTemperature())
MaxHLT = float(getKeyValue(thisBrew, 'HLTReleaseTemp'))
addDebug('Current: %s Max: %s' % (getHLTTemperature(), MaxHLT))
if float(getHLTTemperature()) >= MaxHLT:
# switch off the boil and release the water
GPIO.digitalWrite(HLTBOIL, GPIO.HIGH)
GPIO.digitalWrite(HLTRELEASE, GPIO.HIGH)
moveToNextStage = True
elif latestStage[0] == 'Maintain Mash':
currentMashTemp = float(getMashTemperature())
print currentMashTemp
MaintainMashTemp = float(getKeyValue(thisBrew, 'MashTempMaintain'))
print 'Current Mash %.2f Maintain Temp %.2f' % (currentMashTemp, MaintainMashTemp)
#if Mash Temp too hot turn off boil
if currentMashTemp > (MaintainMashTemp + TOLERANCE):
print 'Mash temp high, turn off boil'
GPIO.digitalWrite(MASHMAINTAIN, GPIO.LOW)
#if Mash Temp too low turn on boil
if currentMashTemp < MaintainMashTemp:
print 'Mash temp low, turn on boil'
GPIO.digitalWrite(MASHMAINTAIN, GPIO.HIGH)
# release if we are at temp and elapsed time = maintain duration
if totalMinutes >= int(getKeyValue(thisBrew, 'MashDuration')) and currentMashTemp >= MaintainMashTemp:
GPIO.digitalWrite(MASHMAINTAIN, GPIO.LOW)
GPIO.digitalWrite(MASHRELEASE, GPIO.HIGH)
moveToNextStage = True
print 'Latest Stage is %s' % latestStage[0]
if latestStage[0] == 'Maintain Mash':
print 'Equal'
So I have this strange problem where my second elif (elif latestStage[0] == 'Maintain Mash':
) never runs the code within it. The first if and elif work fine.
I even added a check at the bottom so I can see 'Equal' being output. I cannot see for the life of me why that second elif never executes.
The getCurrentStage(thisBrew) function will return a string and a datetime value, hence latestStage[0] which is the string and latestStage[1] which is the date of last update.