From 90d8f45b772827a60651b4a874559e5c88f64d80 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 2 Jun 2024 15:25:22 +0200 Subject: [PATCH] Continue Flask migration. --- thermostat.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/thermostat.py b/thermostat.py index 3feb4bb..a14b5a0 100644 --- a/thermostat.py +++ b/thermostat.py @@ -98,6 +98,11 @@ def status_as_text(): +'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()]) +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): try: returned_output = subprocess.check_output(["./relay.py", relay, "status"]) @@ -195,7 +200,7 @@ class Set_mode_thermostat(Resource): class Status_thermostat(Resource): @auth_required def get(self): - result = dict(datas=status_as_text()) + result = status_as_dict() logging.debug(result) return result @@ -237,8 +242,8 @@ def thermostat_loop(): data = Set_mode({"value": new_forced_mode}) db.session.add(data) db.session.commit() -# #cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')") -# #dbconn.commit() + #cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')") + #dbconn.commit() logging.info("Switch to "+new_forced_mode) target_name = new_forced_mode new_forced_mode = None