From 69c791e7ca15fd65dc499777860c5445b5312f9e Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 2 Jun 2024 10:51:25 +0200 Subject: [PATCH] Continue Flask migration. --- thermostat.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/thermostat.py b/thermostat.py index 340400f..7a5066c 100644 --- a/thermostat.py +++ b/thermostat.py @@ -118,7 +118,8 @@ def get_metric(metric, current_time, interval): return None def get_forced_mode(): - row = db.session.query(Set_mode.value, Set_mode.timestamp).first() + with app.app_context(): + 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)) @@ -205,9 +206,10 @@ while True: # break if new_forced_mode is not None: - data = Set_mode({"value": new_forced_mode}) - db.session.add(data) - db.session.commit() + with app.app_context(): + 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)