Add debug.

This commit is contained in:
yohan 2024-06-05 07:54:35 +02:00
parent 49dc3fa220
commit 0117512928

View File

@ -273,25 +273,22 @@ def thermostat_loop():
if new_forced_mode is not None:
with app.app_context():
data = Set_mode(value=new_forced_mode)
logging.debug("Update mode in DB")
try:
logging.debug("Insert mode in DB")
db.session.add(data)
db.session.commit()
except sqlalchemy.exc.IntegrityError as e:
try:
logging.debug("Row already exists in DB.")
db.session.rollback()
logging.debug("Update mode in DB")
cur_mode = db.session.execute(db.select(Set_mode).filter_by(name="mode")).scalar_one()
logging.debug("Current mode: "+str(cur_mode.value))
cur_mode = data
db.session.commit()
except Exception as e:
db.session.rollback()
logging.error(e)
cur_mode = db.session.execute(db.select(Set_mode).filter_by(name="mode")).scalar_one()
logging.debug("Remove current mode: "+str(cur_mode.value))
db.session.delete(cur_mode)
except Exception as e:
db.session.rollback()
logging.error(e)
db.session.rollback()
logging.debug(e)
try:
logging.debug("Insert mode in DB")
db.session.add(data)
db.session.commit()
except Exception as e:
db.session.rollback()
db.session.commit()
logging.error(e)
#cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')")
#dbconn.commit()