Continue Flask migration.

This commit is contained in:
yohan 2024-06-02 23:29:16 +02:00
parent a4eefa18b7
commit 354e0a9f05

View File

@ -187,7 +187,7 @@ Set_mode_model = api.model('Set_mode_Model', Set_mode_resource_fields)
@ns_thermostat.route('/set_mode')
class Set_mode_thermostat(Resource):
@auth_required
@auth_required
@api.expect(Set_mode_model, validate=True)
def post(self):
try:
@ -198,25 +198,6 @@ class Set_mode_thermostat(Resource):
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):
@auth_required
@ -225,6 +206,23 @@ class Status_thermostat(Resource):
logging.debug(result)
return result
Set_verbosity_resource_fields = {
'value': fields.String(required=True, description='Verbosity', enum=[logging.DEBUG, logging.INFO, logging.WARNING])
}
Set_verbosity_model = api.model('Set_verbosity_Model', Set_verbosity_resource_fields)
@ns_thermostat.route('/set_verbosity')
class Set_verbosity_thermostat(Resource):
@auth_required
#@api.expect(Set_verbosity_model, validate=True)
@api.marshall_with(Set_verbosity_model)
def put(self):
print(api.payload)
return "OK", 201
api.add_namespace(ns_thermostat)
with app.app_context():
db.create_all()
@ -264,6 +262,25 @@ def thermostat_loop():
data = Set_mode({"value": new_forced_mode})
db.session.add(data)
db.session.commit()
# 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
#cursor.execute("INSERT OR REPLACE INTO set_mode (value) VALUES ('"+new_forced_mode+"')")
#dbconn.commit()
logging.info("Switch to "+new_forced_mode)