Heating and Ventilation Control
HvcOperationMode
Keine Erläuterungen gefunden.
import os from stat import * import json class HvcOperationMode: def __init__(self): """ Initialization, specify the configuration file. """ self.opModFile = "./ConfDir/operationMode.yml" self.paramFile = "./ConfDir/parameters.yml" def read(self): """ Check for changes of the configuration fles, and load it on change. """ try: st = os.stat(self.opModFile) except IOError: print("failed to get information about", self.opModFile) else: lastModo = st[ST_MTIME] changed = 0 if HvcOperationMode.lastModo != lastModo: changed = 1 HvcOperationMode.lastModo = lastModo with open(self.opModFile) as json_file: HvcOperationMode.operationMode = json.load(json_file) try: st = os.stat(self.paramFile) except IOError: print("failed to get information about", self.paramFile) else: lastModp = st[ST_MTIME] changed = 0 if HvcOperationMode.lastModp != lastModp: changed = 1 HvcOperationMode.lastModp = lastModp with open(self.paramFile) as json_file: parTmp = json.load(json_file) for p in parTmp: if p.find("Time")>0: HvcOperationMode.parameters[p] = self.time2float(parTmp[p]) else: HvcOperationMode.parameters[p] = parTmp[p] return HvcOperationMode.operationMode,HvcOperationMode.parameters,changed def time2float(self,ot): otH = ot[:ot.find(":")] otM = ot[ot.find(":")+1:] time = float(otH) + float(otM) / 60.0 return time def write(self,operationMode): """ Typically, the configuration file is edited via the web-frontend, use this to initially create an yaml file. """ with open(self.opModFile, 'w') as outfile: json.dump(operationMode, outfile) def log(self,operationMode,today,hour,minute): """ To have a protocol, when what was changed """ myOpMode = operationMode myOpMode["date"] = today+"_"+hour+":"+minute pNames = self.parameters.keys() for p in pNames: myOpMode[p] = self.parameters[p] with open("LogDir/settings.log", 'a') as outfile: outfile.write("\n") json.dump(myOpMode, outfile) #persistant values: HvcOperationMode.lastModo = 0 HvcOperationMode.lastModp = 0 HvcOperationMode.operationMode = {} HvcOperationMode.parameters = {} """ for testing """ if __name__ == "__main__": import time, threading om = HvcOperationMode() operationMode = {} operationMode['solar']= "auto" # {on / off / auto} operationMode['oven'] = "off" # {on / off / auto} operationMode['extLight'] = "off" # {on / off / auto} operationMode['pump'] = "off" # {on / off / auto} operationMode['vent'] = "minimal" # {minimal/normal/maximal/auto} operationMode['byPs'] = "shut" # {open/shut} operationMode['opMod'] = "summer" # {winter/summer/vacation} om.write(operationMode) next_call = time.time() while True: newOm,params,changed = om.read() if changed: print(newOm) next_call = next_call+1; time.sleep(next_call - time.time())
python
php
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.