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

Factor out string to DoorState conversion, and support present command

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-09-02 21:21:26 +00:00
parent 9a29f02449
commit 20c86eb659

View File

@ -138,6 +138,16 @@ class DoorState(Enum):
Present = 2
Closed = 3
def from_string(string):
if string == 'lock':
return DoorState.Closed
elif string == 'unlock':
return DoorState.Open
elif string == 'present':
return DoorState.Present
return None
def is_open(self):
if self != DoorState.Closed:
return True
@ -429,15 +439,11 @@ def api():
'Invalid username or password format')
credentials = AuthMethod.LDAP_USER_PW, user, password
desired_state = None
if command == 'status':
return json_response(logic.try_auth(credentials))
elif command == 'lock':
desired_state = DoorState.Closed
elif command == 'unlock':
desired_state = DoorState.Open
desired_state = DoorState.from_string(command)
if not desired_state:
return json_response(LogicResponse.Inval, "Invalid command requested")