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

Make sounds working again

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-10-07 03:47:05 +02:00
parent 8b49549876
commit 69cbf48bae
3 changed files with 33 additions and 9 deletions

2
TODO
View File

@ -1,5 +1,3 @@
- add sounds for button switch
- add sounds for present state
- automatically setup doorlock user
- automatically deploy nginx
- unclutter stuff for X (hide cursor)

View File

@ -88,10 +88,16 @@ ldap_uri = webapp.config.get('LDAP_URI')
ldap_binddn = webapp.config.get('LDAP_BINDDN')
wave_emergency = 'emergency_unlock.wav'
wave_lock = 'lock.wav'
wave_lock_button = 'lock_button.wav'
wave_present = 'present.wav'
wave_present_button = 'present.wav'
wave_unlock = 'unlock.wav'
wave_unlock_button = 'unlock_button.wav'
wave_zonk = 'zonk.wav'
sounds = webapp.config.get('SOUNDS')
@ -141,6 +147,26 @@ def start_hook(script):
Popen(['nohup', join(scripts_prefix, script)])
def sound_helper(old_state, new_state, button):
if old_state == new_state:
playsound(wave_zonk)
if button:
if new_state == DoorState.Open:
playsound(wave_unlock_button)
elif new_state == DoorState.Present:
playsound(wave_present_button)
elif new_state == DoorState.Closed:
playsound(wave_lock_button)
else:
if new_state == DoorState.Open:
playsound(wave_unlock)
elif new_state == DoorState.Present:
playsound(wave_present)
elif new_state == DoorState.Closed:
playsound(wave_lock)
class AuthMethod(Enum):
LDAP_USER_PW = 1
LOCAL_USER_DB = 2
@ -252,6 +278,8 @@ class DoorHandler:
rx = self.serial.read(1)
if len(rx) == 0:
break
old_state = self.state
if rx == DoorHandler.BUTTON_CLOSE:
self.close()
log.info('Closed due to Button press')
@ -270,6 +298,8 @@ class DoorHandler:
else:
log.error('Received unknown message "%s" from AVR' % rx)
sound_helper(old_state, self.state, True)
if self.do_close:
tx = DoorHandler.CMD_CLOSE
self.do_close = False
@ -378,14 +408,10 @@ class Logic:
return self.door_handler.request(state)
def request(self, state, credentials):
old_state = self.door_handler.state
err = self._request(state, credentials)
if err == LogicResponse.Success:
if self.door_handler.state == DoorState.Open:
playsound(wave_unlock)
if self.door_handler.state == DoorState.Closed:
playsound(wave_lock)
elif err == LogicResponse.AlreadyActive:
playsound(wave_zonk)
if err == LogicResponse.Success or err == LogicResponse.AlreadyActive:
sound_helper(old_state, self.door_handler.state, False)
self.emit_status(err)
return err

Binary file not shown.