Continue Flask migration.

This commit is contained in:
yohan 2024-06-02 15:25:22 +02:00
parent 25fad3a6bf
commit 90d8f45b77

View File

@ -98,6 +98,11 @@ def status_as_text():
+'forced_mode: '+str(forced_mode)+'\n'\ +'forced_mode: '+str(forced_mode)+'\n'\
+'\n'.join(['Target temperature for '+room+': '+str(rooms_settings[room][target_name])+'\n'+'Current temperature for '+room+': '+str(get_metric(rooms_settings[room]["metric"], current_time, relay_control_interval)) for room in enabled_rooms()]) +'\n'.join(['Target temperature for '+room+': '+str(rooms_settings[room][target_name])+'\n'+'Current temperature for '+room+': '+str(get_metric(rooms_settings[room]["metric"], current_time, relay_control_interval)) for room in enabled_rooms()])
def status_as_dict():
return {"target": target_name,\
"forced_mode": str(forced_mode),\
"enabled_rooms": {room: {'Target temperature': str(rooms_settings[room][target_name]), 'Current temperature': str(get_metric(rooms_settings[room]["metric"], current_time, relay_control_interval))} for room in enabled_rooms()}}
def relay_state(relay): def relay_state(relay):
try: try:
returned_output = subprocess.check_output(["./relay.py", relay, "status"]) returned_output = subprocess.check_output(["./relay.py", relay, "status"])
@ -195,7 +200,7 @@ class Set_mode_thermostat(Resource):
class Status_thermostat(Resource): class Status_thermostat(Resource):
@auth_required @auth_required
def get(self): def get(self):
result = dict(datas=status_as_text()) result = status_as_dict()
logging.debug(result) logging.debug(result)
return result return result
@ -237,8 +242,8 @@ def thermostat_loop():
data = Set_mode({"value": new_forced_mode}) data = Set_mode({"value": new_forced_mode})
db.session.add(data) db.session.add(data)
db.session.commit() db.session.commit()
# #cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')") #cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')")
# #dbconn.commit() #dbconn.commit()
logging.info("Switch to "+new_forced_mode) logging.info("Switch to "+new_forced_mode)
target_name = new_forced_mode target_name = new_forced_mode
new_forced_mode = None new_forced_mode = None