1
0
mirror of https://github.com/binary-kitchen/doorlockd synced 2024-12-22 02:14:26 +01:00

pydoorlock: Align API requests to latest changes

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-10-09 01:46:09 +02:00
parent f294617e7f
commit 4a0c096331

View File

@ -24,6 +24,7 @@ from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import DataRequired, Length from wtforms.validators import DataRequired, Length
from .Door import DoorState from .Door import DoorState
from .Doorlock import DoorlockResponse
from .Authenticator import AuthMethod from .Authenticator import AuthMethod
log = logging.getLogger() log = logging.getLogger()
@ -89,9 +90,9 @@ def api():
def json_response(response, msg=None): def json_response(response, msg=None):
json = dict() json = dict()
json['err'] = response.value json['err'] = response.value
json['msg'] = response.to_html() if msg is None else msg json['msg'] = str(response) if msg is None else msg
if response == LogicResponse.Success or \ if response == DoorlockResponse.Success or \
response == LogicResponse.AlreadyActive: response == DoorlockResponse.AlreadyActive:
# TBD: Remove 'open'. No more users. Still used in App Version 2.1.1! # TBD: Remove 'open'. No more users. Still used in App Version 2.1.1!
json['open'] = logic.state.is_open() json['open'] = logic.state.is_open()
json['status'] = logic.state.value json['status'] = logic.state.value
@ -113,17 +114,17 @@ def api():
if not user or not password: if not user or not password:
log.warning('Invalid username or password format') log.warning('Invalid username or password format')
return json_response(LogicResponse.Inval, return json_response(DoorlockResponse.Inval,
'Invalid username or password format') 'Invalid username or password format')
credentials = method, user, password credentials = method, user, password
if command == 'status': if command == 'status':
return json_response(logic.try_auth(credentials)) return json_response(logic.auth.try_auth(credentials))
desired_state = DoorState.from_string(command) desired_state = DoorState.from_string(command)
if not desired_state: if not desired_state:
return json_response(LogicResponse.Inval, "Invalid command requested") return json_response(DoorlockResponse.Inval, "Invalid command requested")
log.info('Incoming API request from %s' % user.encode('utf-8')) log.info('Incoming API request from %s' % user.encode('utf-8'))
log.info(' desired state: %s' % desired_state) log.info(' desired state: %s' % desired_state)