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:
parent
9a29f02449
commit
20c86eb659
16
doorlockd.py
16
doorlockd.py
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user