def __init__(self): self.__param = loadparam.Param() self.__logger = LogManager() self.__error_code = "2x" GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) GPIO.setup(self.__param.Open["GPIO"], GPIO.OUT) GPIO.setup(self.__param.Close["GPIO"], GPIO.OUT) GPIO.output(self.__param.Open["GPIO"], GPIO.LOW) GPIO.output(self.__param.Close["GPIO"], GPIO.LOW)
def CheckGreenHouseTemperature(temp): param = loadparam.Param() isClosed = GHM.GetDoorPosition() == GHM.Position.CLOSED # it's getting warmer and it's still closed => open the greenhouse if(temp > float(param.TemperatureTreshold) and isClosed): lam = LAManager.LAManager() lam.Open() Logger.Log('temp ({0}) is higher than treshold ({1}) => opening greenhouse now'.format(temp, param.TemperatureTreshold)) # it's getting colder and it's still opened => close the greenhouse elif(temp < float(param.TemperatureTreshold) and not isClosed): lam = LAManager.LAManager() lam.Close() Logger.Log('temp ({0}) is lower than treshold ({1}) => closing greenhouse now'.format(temp, param.TemperatureTreshold))
def SaveNewMeasure(hum, temp): param = loadparam.Param() with open(param.TemperatureDataFile,'a+') as f: f.write('{0},{1},{2:0.1f},{3:0.1f}\r\n'.format(time.strftime('%d/%m/%y'), time.strftime('%H:%M:%S'), temp, hum))
def GetLatestMeasure(): param = loadparam.Param() with open(param.TemperatureDataFile) as f: return f.readlines()[-1]
from enum import Enum import loadparam p = loadparam.Param() class Position(Enum): OPENED = 1 CLOSED = 0 def GetDoorPosition(): with open(p.PositionFile) as f: position = f.read() return Position.CLOSED if int(position) == 0 else Position.OPENED