clean up stateMachine syntax
This commit is contained in:
parent
276eb2fb1a
commit
9fb26a95c1
|
@ -78,10 +78,8 @@ class StateMachine:
|
||||||
if self._timer.is_alive():
|
if self._timer.is_alive():
|
||||||
self._timer.stop()
|
self._timer.stop()
|
||||||
self._timer = None
|
self._timer = None
|
||||||
|
|
||||||
States = namedtuple('States', ['disarmed', 'disarmedCountdown', 'armed', 'armedCountdown', 'triggered'])
|
stateObjs = [
|
||||||
|
|
||||||
self.states = States(
|
|
||||||
State(
|
State(
|
||||||
self,
|
self,
|
||||||
name = 'disarmed',
|
name = 'disarmed',
|
||||||
|
@ -108,7 +106,9 @@ class StateMachine:
|
||||||
name = 'triggered',
|
name = 'triggered',
|
||||||
entryCallbacks = [intruderAlert]
|
entryCallbacks = [intruderAlert]
|
||||||
)
|
)
|
||||||
)
|
]
|
||||||
|
|
||||||
|
self.states = namedtuple('States', [s.name for s in stateObjs])(*stateObjs)
|
||||||
|
|
||||||
self.currentState = getattr(self.states, stateFile['state'])
|
self.currentState = getattr(self.states, stateFile['state'])
|
||||||
|
|
||||||
|
@ -203,20 +203,8 @@ class StateMachine:
|
||||||
logger.info('state changed to %s', self.currentState)
|
logger.info('state changed to %s', self.currentState)
|
||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
if hasattr(self, 'LED'):
|
for i in ['LED', 'camera', 'fileDump', 'soundLib', 'secretListener', 'keypadListener']:
|
||||||
self.LED.__del__()
|
try:
|
||||||
|
getattr(self, i).__del__()
|
||||||
if hasattr(self, 'camera'):
|
except AttributeError:
|
||||||
self.camera.__del__()
|
pass
|
||||||
|
|
||||||
if hasattr(self, 'fileDump'):
|
|
||||||
self.fileDump.__del__()
|
|
||||||
|
|
||||||
if hasattr(self, 'soundLib'):
|
|
||||||
self.soundLib.__del__()
|
|
||||||
|
|
||||||
if hasattr(self, 'secretListener'):
|
|
||||||
self.secretListener.__del__()
|
|
||||||
|
|
||||||
if hasattr(self, 'keypadListener'):
|
|
||||||
self.keypadListener.__del__()
|
|
||||||
|
|
Loading…
Reference in New Issue