Use reqparser. Fix indentation.
This commit is contained in:
parent
df87a1deb8
commit
be8588d039
@ -180,31 +180,24 @@ Set_mode_parser.add_argument(
|
|||||||
|
|
||||||
@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_parser, 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:
|
||||||
# data = Set_mode(**request.json)
|
args = Set_mode_parser.parse_args()
|
||||||
#except Exception as e:
|
new_forced_mode = args["value"]
|
||||||
# logging.error(e)
|
except Exception as e:
|
||||||
# return "K0", 400
|
logging.error(e)
|
||||||
try:
|
return "K0", 400
|
||||||
args = Set_mode_parser.parse_args()
|
return "OK", 201
|
||||||
new_forced_mode = args["value"]
|
|
||||||
xprint(new_forced_mode)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(e)
|
|
||||||
return "K0", 400
|
|
||||||
return "OK", 201
|
|
||||||
|
|
||||||
@ns_thermostat.route('/status')
|
@ns_thermostat.route('/status')
|
||||||
class Status_thermostat(Resource):
|
class Status_thermostat(Resource):
|
||||||
@auth_required
|
@auth_required
|
||||||
def get(self):
|
def get(self):
|
||||||
result = status_as_dict()
|
result = status_as_dict()
|
||||||
logging.debug(result)
|
return result
|
||||||
return result
|
|
||||||
|
|
||||||
Set_verbosity_parser = api.parser()
|
Set_verbosity_parser = api.parser()
|
||||||
Set_verbosity_parser.add_argument(
|
Set_verbosity_parser.add_argument(
|
||||||
@ -213,16 +206,23 @@ Set_verbosity_parser.add_argument(
|
|||||||
|
|
||||||
@ns_thermostat.route('/set_verbosity')
|
@ns_thermostat.route('/set_verbosity')
|
||||||
class Set_verbosity_thermostat(Resource):
|
class Set_verbosity_thermostat(Resource):
|
||||||
@auth_required
|
@auth_required
|
||||||
@api.expect(Set_verbosity_parser, validate=True)
|
@api.expect(Set_verbosity_parser, validate=True)
|
||||||
def put(self):
|
def put(self):
|
||||||
if api.payload["value"] == 'DEBUG':
|
try:
|
||||||
logging.getLogger().setLevel(logging.DEBUG)
|
args = Set_verbosity_parser.parse_args()
|
||||||
elif api.payload["value"] == 'INFO':
|
if args["value"] == 'DEBUG':
|
||||||
logging.getLogger().setLevel(logging.INFO)
|
logging.getLogger().setLevel(logging.DEBUG)
|
||||||
elif api.payload["value"] == 'WARNING':
|
elif args["value"] == 'INFO':
|
||||||
logging.getLogger().setLevel(logging.WARNING)
|
logging.getLogger().setLevel(logging.INFO)
|
||||||
return "OK", 201
|
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)
|
api.add_namespace(ns_thermostat)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user