diff --git a/doorlockd b/doorlockd index ceddb7a..d33e13c 100755 --- a/doorlockd +++ b/doorlockd @@ -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 diff --git a/pydoorlock/Door.py b/pydoorlock/Door.py new file mode 100644 index 0000000..66f5c2e --- /dev/null +++ b/pydoorlock/Door.py @@ -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'