From adbc3b754b57ec89993568841c28f55b86ae54c3 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 2 Jun 2024 10:39:59 +0200 Subject: [PATCH] Continue Flask migration. --- thermostat.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/thermostat.py b/thermostat.py index 21ae9d1..3c6acd3 100644 --- a/thermostat.py +++ b/thermostat.py @@ -117,9 +117,10 @@ def get_metric(metric, current_time, interval): sys.stdout.flush() return None -def get_forced_mode(cur): - cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'") - row = cur.fetchone() +def get_forced_mode(): + row = db.session.query(Set_mode.value, Set_mode.timestamp).first() + #cur.execute("SELECT value, timestamp FROM set_mode WHERE name='mode'") + #row = cur.fetchone() data = dict(zip(['value', 'timestamp'], row)) timestamp = getDateTimeFromISO8601String(data['timestamp']).replace(tzinfo=timezone.utc).timestamp() # We ignore old targets but never ignore absence modes @@ -204,8 +205,11 @@ while True: # break if new_forced_mode is not None: - cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')") - dbconn.commit() + 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() logging.info("Switch to "+new_forced_mode) target_name = new_forced_mode new_forced_mode = None