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