Continue Flask migration.
This commit is contained in:
parent
72958960d4
commit
4e8a616b23
@ -16,6 +16,7 @@ import requests
|
||||
import subprocess
|
||||
from threading import Thread
|
||||
import sqlalchemy.exc
|
||||
from sqlalchemy.dialects.sqlite import insert as sqlite_upsert
|
||||
|
||||
# This code has been written for
|
||||
# python3 3.11.2-1+b1
|
||||
@ -150,7 +151,7 @@ def get_forced_mode():
|
||||
#row = cur.fetchone()
|
||||
print(row)
|
||||
data = dict(zip(['value', 'timestamp'], row))
|
||||
timestamp = datetime.fromisoformat(data['timestamp']).replace(tzinfo=timezone.utc).timestamp()
|
||||
timestamp = data['timestamp'].replace(tzinfo=timezone.utc).timestamp()
|
||||
# We ignore old targets but never ignore absence modes
|
||||
if data['value'] in targets and time.time() - timestamp > forced_mode_duration:
|
||||
logging.debug("Ignoring old set mode.")
|
||||
@ -199,7 +200,12 @@ class Set_mode_thermostat(Resource):
|
||||
db.session.commit()
|
||||
return "OK", 201
|
||||
except sqlalchemy.exc.IntegrityError as e:
|
||||
logging.error("catched")
|
||||
try:
|
||||
cur_mode = db.session.execute(db.select(Set_mode).filter_by(name="mode")).scalar_one()
|
||||
cur_mode = data
|
||||
db.session.commit()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
return "K0", 400
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
Loading…
Reference in New Issue
Block a user