doorlockd.py: add doorlock sounds

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-03-23 22:00:25 +00:00
parent 8f8db8950b
commit 010563dab4
9 changed files with 36 additions and 5 deletions

View File

@ -1,4 +1,3 @@
- Add sounds
- Remove php-fpm
- adjust nginx config
- Add proper SSL certificates

View File

@ -1,6 +1,7 @@
DEBUG = True
SIMULATE = True
RUN_HOOKS = False
DEBUG = False
SIMULATE = False
RUN_HOOKS = True
SOUNDS = True
SECRET_KEY = 'foobar'
LDAP_CA = './ssl/BKCA.crt'
@ -9,4 +10,11 @@ LDAP_BINDDN = 'cn=%s,ou=people,dc=binary-kitchen,dc=de'
BOOTSTRAP_SERVE_LOCAL = True
SERIAL_PORT = '/dev/ttyS0'
SERIAL_PORT = '/dev/ttyAMA0'
WAVE_EMERGENCY = './sounds/emergency_unlock.wav'
WAVE_LOCK = './sounds/lock.wav'
WAVE_LOCK_BUTTON = './sounds/lock_button.wav'
WAVE_UNLOCK = './sounds/unlock.wav'
WAVE_UNLOCK_BUTTON = './sounds/unlock_button.wav'
WAVE_ZONK = './sounds/zonk.wav'

View File

@ -71,6 +71,14 @@ if 'LDAP_CA' in webapp.config.keys():
ldap_uri = webapp.config.get('LDAP_URI')
ldap_binddn = webapp.config.get('LDAP_BINDDN')
wave_emergency = webapp.config.get('WAVE_EMERGENCY')
wave_lock = webapp.config.get('WAVE_LOCK')
wave_lock_button = webapp.config.get('WAVE_LOCK_BUTTON')
wave_unlock = webapp.config.get('WAVE_UNLOCK')
wave_unlock_button = webapp.config.get('WAVE_UNLOCK_BUTTON')
wave_zonk = webapp.config.get('WAVE_ZONK')
sounds = webapp.config.get('SOUNDS')
# copied from sudo
eperm_insults = {
'Wrong! You cheating scum!',
@ -98,6 +106,12 @@ def choose_insult():
return(sample(eperm_insults, 1)[0])
def playsound(filename):
if not sounds:
return
Popen(['nohup', 'aplay', filename])
def start_hook(script):
if not run_hooks:
log.info('Hooks disabled: not starting %s' % script)
@ -183,11 +197,14 @@ class DoorHandler:
def handle_input(self, recv, expect=None):
if recv == DoorHandler.BUTTON_LOCK_PRESS:
playsound(wave_lock_button)
self.state = DoorState.Close
logic.emit_status(LogicResponse.ButtonLock)
elif recv == DoorHandler.BUTTON_UNLOCK_PRESS:
playsound(wave_unlock_button)
logic.emit_status(LogicResponse.ButtonUnlock)
elif recv == DoorHandler.BUTTON_EMERGENCY_PRESS:
playsound(wave_emergency)
logic.emit_status(LogicResponse.EmergencyUnlock)
if expect is None:
@ -281,6 +298,13 @@ class Logic:
def request(self, state, credentials):
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.Close:
playsound(wave_lock)
elif err == LogicResponse.AlreadyLocked or err == LogicResponse.AlreadyOpen:
playsound(wave_zonk)
self.emit_status(err)
return err

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.