Continue Flask migration.

This commit is contained in:
yohan 2024-06-02 22:52:39 +02:00
parent 2c747d75e4
commit a4eefa18b7

View File

@ -179,7 +179,7 @@ class Set_mode(db.Model):
Set_mode_resource_fields = {
'name': fields.String(description='mode type'),
'value': fields.String(required=True, description='value'),
'value': fields.String(required=True, description='value', enum=targets+modes),
'time': fields.DateTime(dt_format='iso8601'),
}
@ -195,24 +195,27 @@ class Set_mode_thermostat(Resource):
except Exception as e:
logging.error(e)
return "K0", 400
try:
db.session.add(data)
db.session.commit()
return "OK", 201
except sqlalchemy.exc.IntegrityError as e:
try:
db.session.rollback()
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:
db.session.rollback()
logging.error(e)
return "K0", 400
except Exception as e:
db.session.rollback()
logging.error(e)
return "K0", 400
new_forced_mode = data.value
return "OK", 201
# try:
# db.session.add(data)
# db.session.commit()
# return "OK", 201
# except sqlalchemy.exc.IntegrityError as e:
# try:
# db.session.rollback()
# 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:
# db.session.rollback()
# logging.error(e)
# return "K0", 400
# except Exception as e:
# db.session.rollback()
# logging.error(e)
# return "K0", 400
@ns_thermostat.route('/status')
class Status_thermostat(Resource):
@ -238,14 +241,15 @@ migrate = Migrate(app, db, compare_type=True)
target_name = default_target
forced_mode = None
current_time = time.time()
new_forced_mode = None
def thermostat_loop():
start_time = time.time()
last_control_time = None
new_forced_mode = None
first_loop = True
global target_name
global forced_mode
global new_forced_mode
global current_time
while True: