def show_therm(wserv, minutes, thermo_name): db = dyndb.Tempdb(tconf.url, tconf.region) if minutes is None: minutes = 60 if thermo_name is None: thermo_name = tconf.thermo_name response = db.thermo_get_minutes(minutes, thermo_name) wserv.wfile.write("<h1>Temperature data</h1><p><table border=1>") wserv.wfile.write( "<th>Date</th><th>T1</th><th>T2</th><th>Target T</th><th>mode</th><th>Boiler</th>" ) cmdmap = {2: 'Night', 1: 'Day', 0: 'Off', 3: 'Undef'} bmap = {1: '+', 0: '-', 2: 'Undef'} for i in reversed(response['Items']): wserv.wfile.write( "<tr><td>{0}</td><td>{1}</td> <td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>" .format( time.strftime("%d.%m %H:%M:%S", time.localtime(float(i['GetDate']))), float(i.get('val1', -1)), float(i.get('val2', -1)), int(i.get('target', -1)), cmdmap.get(int(i.get('heating', -1)), 3), bmap.get(int(i.get('boiler_state', -1)), 2)).encode(encoding='UTF-8')) print(time.ctime(float(i['GetDate'])), 'temp1', float(i.get('val1', -1)), 'temp2', float(i.get('val2', -1)), 'target temp', int(i.get('target', -1)), 'heating cmd', int(i.get('heating', -1)), 'boiler state', int(i.get('boiler_state', -1))) wserv.wfile.write("</table>")
def set_boiler(cmd, target=None, heating_s=None, thermo_name=None): if thermo_name is None: thermo_name=tconf.thermo_name b=bstate.Boiler(thermo_name) #Assume thermo_name always equal to boiler_name db=dyndb.Tempdb(tconf.url,tconf.region) heating = cmdmap.get(heating_s, -1) ret_s = '' if cmd=='sync': #update local state from db db2local(b,db) elif cmd=='loop': #sync local state from db in loop while 1: db2local(b,db) sys.sleep(tconf.therm_rate*1.5) elif cmd=='local': #write values to local state file only print (b.write_state(target,heating)) elif cmd=='dbw': #write values to db and locally response=db.thermo_cmd(target,heating,b.boiler_name,b.boiler_name) print (b.write_state(target,heating)) elif cmd=='read': print ('Local file: ', b.read_state()) print ('Boiler: ', b.boiler_name ) response=db.get_cmd(b.boiler_name,b.boiler_name) if response.has_key('Item'): i=response['Item'] ret_s = "Remote command: target: '{1}', is heating: '{2}', updated at '{0}'".format( time.ctime(float(i['utime'])),float(i.get('target',-1)), int(i.get('heating',-1))) print (ret_s) else: ret_s = "No boiler '{0}' targets in cloud".format(b.boiler_name) print (ret_s, file=sys.stderr) else: print ('Unknown command: ', cmd,file=sys.stderr) raise Exception('Unknown command') return ret_s
def __init__(self): self.thermo_name = tconf.thermo_name self.minutes = 60 self.db = dyndb.Tempdb(tconf.url, tconf.region)
return float(o) else: return int(o) return super(DecimalEncoder, self).default(o) thermo_name = tconf.thermo_name minutes = 60 frm = 'table' if len(sys.argv) == 2: minutes = int(sys.argv[1]) elif len(sys.argv) == 3: minutes = int(sys.argv[1]) frm = sys.argv[2] db = dyndb.Tempdb(tconf.url, tconf.region) response = db.thermo_get_minutes(minutes, thermo_name) if frm == 'data': for i in response['Items']: print("{1} {0}".format(float(i['GetDate']), float(i.get('val1', -1)))) else: for i in response['Items']: print(time.ctime(float(i['GetDate'])), 'temp1', float(i.get('val1', -1)), 'temp2', float(i.get('val2', -1)), 'target temp', int(i.get('target', -1)), 'heating cmd', int(i.get('heating', -1)), 'boiler state', int(i.get('boiler_state', -1)))