diff --git a/thermostat.py b/thermostat.py index 2e24617..df59429 100644 --- a/thermostat.py +++ b/thermostat.py @@ -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) # timestamp = db.Column(db.DateTime, server_default=db.text("CURRENT_TIMESTAMP"), nullable=False) -Set_mode_resource_fields = { - 'name': fields.String(description='mode type'), - 'value': fields.String(required=True, description='value', enum=targets+modes), - 'time': fields.DateTime(dt_format='iso8601'), -} +#Set_mode_resource_fields = { +# 'value': fields.String(required=True, description='value', enum=targets+modes), +#} -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') class Set_mode_thermostat(Resource): @auth_required - @api.expect(Set_mode_model, validate=True) + @api.expect(Set_mode_parser, validate=True) def post(self): global new_forced_mode #try: @@ -216,7 +219,8 @@ class Set_mode_thermostat(Resource): # logging.error(e) # return "K0", 400 try: - new_forced_mode = data.value + args = Set_mode_parser.parse_args() + new_forced_mode = args["value"] xprint(new_forced_mode) except Exception as e: logging.error(e)