Use reqparse.
This commit is contained in:
parent
e05775f031
commit
467e34eced
@ -196,18 +196,21 @@ cursor.execute("CREATE TABLE IF NOT EXISTS set_mode (name TEXT PRIMARY KEY DEFAU
|
|||||||
# value = db.Column(db.String, nullable=False)
|
# value = db.Column(db.String, nullable=False)
|
||||||
# timestamp = db.Column(db.DateTime, server_default=db.text("CURRENT_TIMESTAMP"), nullable=False)
|
# timestamp = db.Column(db.DateTime, server_default=db.text("CURRENT_TIMESTAMP"), nullable=False)
|
||||||
|
|
||||||
Set_mode_resource_fields = {
|
#Set_mode_resource_fields = {
|
||||||
'name': fields.String(description='mode type'),
|
# 'value': fields.String(required=True, description='value', enum=targets+modes),
|
||||||
'value': fields.String(required=True, description='value', enum=targets+modes),
|
#}
|
||||||
'time': fields.DateTime(dt_format='iso8601'),
|
|
||||||
}
|
|
||||||
|
|
||||||
Set_mode_model = api.model('Set_mode_Model', Set_mode_resource_fields)
|
#Set_mode_model = api.model('Set_mode_Model', Set_mode_resource_fields)
|
||||||
|
|
||||||
|
Set_mode_parser = api.parser()
|
||||||
|
Set_mode_parser.add_argument(
|
||||||
|
"value", type=str, choices=targets+modes, required=True, help="value", location="form"
|
||||||
|
)
|
||||||
|
|
||||||
@ns_thermostat.route('/set_mode')
|
@ns_thermostat.route('/set_mode')
|
||||||
class Set_mode_thermostat(Resource):
|
class Set_mode_thermostat(Resource):
|
||||||
@auth_required
|
@auth_required
|
||||||
@api.expect(Set_mode_model, validate=True)
|
@api.expect(Set_mode_parser, validate=True)
|
||||||
def post(self):
|
def post(self):
|
||||||
global new_forced_mode
|
global new_forced_mode
|
||||||
#try:
|
#try:
|
||||||
@ -216,7 +219,8 @@ class Set_mode_thermostat(Resource):
|
|||||||
# logging.error(e)
|
# logging.error(e)
|
||||||
# return "K0", 400
|
# return "K0", 400
|
||||||
try:
|
try:
|
||||||
new_forced_mode = data.value
|
args = Set_mode_parser.parse_args()
|
||||||
|
new_forced_mode = args["value"]
|
||||||
xprint(new_forced_mode)
|
xprint(new_forced_mode)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(e)
|
logging.error(e)
|
||||||
|
Loading…
Reference in New Issue
Block a user