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