From 944018f762f744136250b0e5f796162498a47d15 Mon Sep 17 00:00:00 2001 From: yohan <783b8c87@scimetis.net> Date: Sun, 2 Jun 2024 14:45:26 +0200 Subject: [PATCH] Continue Flask migration. --- thermostat.py | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/thermostat.py b/thermostat.py index fea5977..f558237 100644 --- a/thermostat.py +++ b/thermostat.py @@ -220,29 +220,29 @@ first_loop = True def thermostat_loop(): while True: -# # if stop.is_set(): -# # httpd.shutdown() -# # httpd.server_close() -# # dbconn.close() -# # break -# -# if new_forced_mode is not None: -# with app.app_context(): -# data = Set_mode({"value": new_forced_mode}) -# db.session.add(data) -# db.session.commit() + # if stop.is_set(): + # httpd.shutdown() + # httpd.server_close() + # dbconn.close() + # break + + if new_forced_mode is not None: + 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) -# target_name = new_forced_mode -# new_forced_mode = None -# # Force immediate action: -# last_control_time = None -# current_time = time.time() -# current_date = datetime.now() -# today_awake_time = current_date.replace(hour=int(awake_hour.split(':')[0]), minute=int(awake_hour.split(':')[1]), second=0, microsecond=0) -# today_sleep_time = current_date.replace(hour=int(sleep_hour.split(':')[0]), minute=int(sleep_hour.split(':')[1]), second=0, microsecond=0) -# forced_mode = get_forced_mode() + logging.info("Switch to "+new_forced_mode) + target_name = new_forced_mode + new_forced_mode = None + # Force immediate action: + last_control_time = None + current_time = time.time() + current_date = datetime.now() + today_awake_time = current_date.replace(hour=int(awake_hour.split(':')[0]), minute=int(awake_hour.split(':')[1]), second=0, microsecond=0) + today_sleep_time = current_date.replace(hour=int(sleep_hour.split(':')[0]), minute=int(sleep_hour.split(':')[1]), second=0, microsecond=0) + forced_mode = get_forced_mode() # if forced_mode is not None and forced_mode in targets: # if target_name != forced_mode: # target_name = forced_mode