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

pydoorlock: extract DoorState

Signed-off-by: Ralf Ramsauer <ralf@binary-kitchen.de>
This commit is contained in:
Ralf Ramsauer 2018-10-08 01:55:42 +02:00
parent 55205ad247
commit d1855bf77d
2 changed files with 38 additions and 37 deletions

View File

@ -34,6 +34,7 @@ from wtforms import PasswordField, StringField, SubmitField
from wtforms.validators import DataRequired, Length
from pydoorlock.Authenticator import Authenticator, AuthMethod, AuthenticationResult
from pydoorlock.Door import DoorState
SYSCONFDIR = '.'
PREFIX = '.'
@ -132,43 +133,6 @@ def sound_helper(old_state, new_state, button):
playsound(wave_lock)
class DoorState(Enum):
# These numbers are used by the App since version 3.0, do NOT change them
Open = 0
Present = 1
Closed = 2
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
return False
def to_img(self):
led = 'red'
if self == DoorState.Present:
led = 'yellow'
elif self == DoorState.Open:
led = 'green'
return 'static/led-%s.png' % led
def to_html(self):
if self == DoorState.Open:
return 'Offen'
elif self == DoorState.Present:
return 'Jemand da'
return 'Geschlossen'
class LogicResponse(Enum):
Success = 0
Perm = 1

37
pydoorlock/Door.py Normal file
View File

@ -0,0 +1,37 @@
from enum import Enum
class DoorState(Enum):
# These numbers are used by the App since version 3.0, do NOT change them
Open = 0
Present = 1
Closed = 2
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
return False
def to_img(self):
led = 'red'
if self == DoorState.Present:
led = 'yellow'
elif self == DoorState.Open:
led = 'green'
return 'static/led-%s.png' % led
def to_html(self):
if self == DoorState.Open:
return 'Offen'
elif self == DoorState.Present:
return 'Jemand da'
return 'Geschlossen'