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)