Use reqparser. Fix indentation.

This commit is contained in:
yohan 2024-06-06 21:52:58 +02:00
parent df87a1deb8
commit be8588d039

View File

@ -180,31 +180,24 @@ Set_mode_parser.add_argument(
@ns_thermostat.route('/set_mode')
class Set_mode_thermostat(Resource):
@auth_required
@api.expect(Set_mode_parser, validate=True)
def post(self):
global new_forced_mode
#try:
# data = Set_mode(**request.json)
#except Exception as e:
# logging.error(e)
# return "K0", 400
try:
args = Set_mode_parser.parse_args()
new_forced_mode = args["value"]
xprint(new_forced_mode)
except Exception as e:
logging.error(e)
return "K0", 400
return "OK", 201
@auth_required
@api.expect(Set_mode_parser, validate=True)
def post(self):
global new_forced_mode
try:
args = Set_mode_parser.parse_args()
new_forced_mode = args["value"]
except Exception as e:
logging.error(e)
return "K0", 400
return "OK", 201
@ns_thermostat.route('/status')
class Status_thermostat(Resource):
@auth_required
def get(self):
result = status_as_dict()
logging.debug(result)
return result
@auth_required
def get(self):
result = status_as_dict()
return result
Set_verbosity_parser = api.parser()
Set_verbosity_parser.add_argument(
@ -213,16 +206,23 @@ Set_verbosity_parser.add_argument(
@ns_thermostat.route('/set_verbosity')
class Set_verbosity_thermostat(Resource):
@auth_required
@api.expect(Set_verbosity_parser, validate=True)
def put(self):
if api.payload["value"] == 'DEBUG':
logging.getLogger().setLevel(logging.DEBUG)
elif api.payload["value"] == 'INFO':
logging.getLogger().setLevel(logging.INFO)
elif api.payload["value"] == 'WARNING':
logging.getLogger().setLevel(logging.WARNING)
return "OK", 201
@auth_required
@api.expect(Set_verbosity_parser, validate=True)
def put(self):
try:
args = Set_verbosity_parser.parse_args()
if args["value"] == 'DEBUG':
logging.getLogger().setLevel(logging.DEBUG)
elif args["value"] == 'INFO':
logging.getLogger().setLevel(logging.INFO)
elif args["value"] == 'WARNING':
logging.getLogger().setLevel(logging.WARNING)
else:
return "Bad request", 400
return "OK", 201
except Exception as e:
logging.error(e)
return "K0", 400
api.add_namespace(ns_thermostat)