mirror of
https://github.com/binary-kitchen/doorlockd
synced 2024-12-22 10:24:26 +01:00
pydoorlock: use definitions in Protocol.py
We now share definitions. Use them. Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
parent
e27f6d02da
commit
263fc0c687
@ -26,6 +26,7 @@ from time import sleep
|
|||||||
from os.path import join
|
from os.path import join
|
||||||
|
|
||||||
from .Door import DoorState
|
from .Door import DoorState
|
||||||
|
from .Protocol import Protocol
|
||||||
|
|
||||||
log = logging.getLogger()
|
log = logging.getLogger()
|
||||||
|
|
||||||
@ -98,16 +99,6 @@ class DoorHandler:
|
|||||||
state = DoorState.Closed
|
state = DoorState.Closed
|
||||||
do_close = False
|
do_close = False
|
||||||
|
|
||||||
CMD_PRESENT = b'y'
|
|
||||||
CMD_OPEN = b'g'
|
|
||||||
CMD_CLOSE = b'r'
|
|
||||||
|
|
||||||
BUTTON_PRESENT = b'Y'
|
|
||||||
BUTTON_OPEN = b'G'
|
|
||||||
BUTTON_CLOSE = b'R'
|
|
||||||
|
|
||||||
CMD_EMERGENCY_SWITCH = b'E'
|
|
||||||
|
|
||||||
wave_lock = 'lock.wav'
|
wave_lock = 'lock.wav'
|
||||||
wave_lock_button = 'lock_button.wav'
|
wave_lock_button = 'lock_button.wav'
|
||||||
|
|
||||||
@ -150,19 +141,19 @@ class DoorHandler:
|
|||||||
break
|
break
|
||||||
|
|
||||||
old_state = self.state
|
old_state = self.state
|
||||||
if rx == DoorHandler.BUTTON_CLOSE:
|
if rx == Protocol.STATE_SWITCH_RED.value.upper():
|
||||||
self.close()
|
self.close()
|
||||||
log.info('Closed due to Button press')
|
log.info('Closed due to Button press')
|
||||||
self.invoke_callback(DoorlockResponse.ButtonLock)
|
self.invoke_callback(DoorlockResponse.ButtonLock)
|
||||||
elif rx == DoorHandler.BUTTON_OPEN:
|
elif rx == Protocol.STATE_SWITCH_GREEN.value.upper():
|
||||||
self.open()
|
self.open()
|
||||||
log.info('Opened due to Button press')
|
log.info('Opened due to Button press')
|
||||||
self.invoke_callback(DoorlockResponse.ButtonUnlock)
|
self.invoke_callback(DoorlockResponse.ButtonUnlock)
|
||||||
elif rx == DoorHandler.BUTTON_PRESENT:
|
elif rx == Protocol.STATE_SWITCH_YELLOW.value.upper():
|
||||||
self.present()
|
self.present()
|
||||||
log.info('Present due to Button press')
|
log.info('Present due to Button press')
|
||||||
self.invoke_callback(DoorlockResponse.ButtonPresent)
|
self.invoke_callback(DoorlockResponse.ButtonPresent)
|
||||||
elif rx == DoorHandler.CMD_EMERGENCY_SWITCH:
|
elif rx == Protocol.EMERGENCY.value:
|
||||||
log.warning('Emergency unlock')
|
log.warning('Emergency unlock')
|
||||||
self.invoke_callback(DoorlockResponse.EmergencyUnlock)
|
self.invoke_callback(DoorlockResponse.EmergencyUnlock)
|
||||||
else:
|
else:
|
||||||
@ -171,12 +162,12 @@ class DoorHandler:
|
|||||||
self.sound_helper(old_state, self.state, True)
|
self.sound_helper(old_state, self.state, True)
|
||||||
|
|
||||||
if self.do_close:
|
if self.do_close:
|
||||||
tx = DoorHandler.CMD_CLOSE
|
tx = Protocol.STATE_SWITCH_RED.value
|
||||||
self.do_close = False
|
self.do_close = False
|
||||||
elif self.state == DoorState.Present:
|
elif self.state == DoorState.Present:
|
||||||
tx = DoorHandler.CMD_PRESENT
|
tx = Protocol.STATE_SWITCH_YELLOW.value
|
||||||
elif self.state == DoorState.Open:
|
elif self.state == DoorState.Open:
|
||||||
tx = DoorHandler.CMD_OPEN
|
tx = Protocol.STATE_SWITCH_GREEN.value
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user