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

Rework AlreadyLocked and AlreadyUnlocked

Better use the AlreadyActive semantics, which signalises that a state,
no matter which state in particular, is already active.

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-09-02 22:29:30 +00:00
parent 6977c46c5c
commit 23166516f1

View File

@ -173,8 +173,9 @@ class DoorState(Enum):
class LogicResponse(Enum): class LogicResponse(Enum):
Success = 0 Success = 0
Perm = 1 Perm = 1
AlreadyLocked = 2 AlreadyActive = 2
AlreadyOpen = 3 # don't break old apps, value 3 is reserved now
RESERVED = 3
Inval = 4 Inval = 4
LDAP = 5 LDAP = 5
@ -188,10 +189,8 @@ class LogicResponse(Enum):
return 'Yo, passt.' return 'Yo, passt.'
elif self == LogicResponse.Perm: elif self == LogicResponse.Perm:
return choose_insult() return choose_insult()
elif self == LogicResponse.AlreadyLocked: elif self == LogicResponse.AlreadyActive:
return 'Narf. Schon zu.' return 'Zustand bereits aktiv'
elif self == LogicResponse.AlreadyOpen:
return 'Schon offen, treten Sie ein!'
elif self == LogicResponse.Inval: elif self == LogicResponse.Inval:
return 'Das was du willst geht nicht.' return 'Das was du willst geht nicht.'
elif self == LogicResponse.LDAP: elif self == LogicResponse.LDAP:
@ -282,7 +281,7 @@ class DoorHandler:
def open(self): def open(self):
if self.state == DoorState.Open: if self.state == DoorState.Open:
return LogicResponse.AlreadyOpen return LogicResponse.AlreadyActive
self.state = DoorState.Open self.state = DoorState.Open
run_unlock() run_unlock()
@ -290,7 +289,7 @@ class DoorHandler:
def close(self): def close(self):
if self.state == DoorState.Closed: if self.state == DoorState.Closed:
return LogicResponse.AlreadyLocked return LogicResponse.AlreadyActive
self.do_close = True self.do_close = True
self.state = DoorState.Closed self.state = DoorState.Closed
@ -299,7 +298,7 @@ class DoorHandler:
def present(self): def present(self):
if self.state == DoorState.Present: if self.state == DoorState.Present:
return LogicResponse.AlreadyOpen return LogicResponse.AlreadyActive
self.state = DoorState.Present self.state = DoorState.Present
# new hook? # new hook?
@ -357,7 +356,7 @@ class Logic:
playsound(wave_unlock) playsound(wave_unlock)
if self.door_handler.state == DoorState.Closed: if self.door_handler.state == DoorState.Closed:
playsound(wave_lock) playsound(wave_lock)
elif err == LogicResponse.AlreadyLocked or err == LogicResponse.AlreadyOpen: elif err == LogicResponse.AlreadyActive:
playsound(wave_zonk) playsound(wave_zonk)
self.emit_status(err) self.emit_status(err)
return err return err
@ -419,8 +418,7 @@ def api():
json['err'] = response.value json['err'] = response.value
json['msg'] = response.to_html() if msg is None else msg json['msg'] = response.to_html() if msg is None else msg
if response == LogicResponse.Success or \ if response == LogicResponse.Success or \
response == LogicResponse.AlreadyLocked or \ response == LogicResponse.AlreadyActive:
response == LogicResponse.AlreadyOpen:
# 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