put signal partials in statemach attributes

This commit is contained in:
petrucci4prez 2017-06-08 02:33:05 -04:00
parent b294a12264
commit 35bce93259
1 changed files with 11 additions and 10 deletions

View File

@ -75,10 +75,14 @@ class StateMachine:
self.camera = Camera() self.camera = Camera()
self.fileDump = FileDump() self.fileDump = FileDump()
# add signals to self to avoid calling partial every time
for s in SIGNALS:
setattr(self, s.name, partial(self.selectState, s))
secretTable = { secretTable = {
"dynamoHum": partial(self.selectState, SIGNALS.DISARM), 'dynamoHum': self.DISARM,
"zombyWoof": partial(self.selectState, SIGNALS.ARM), 'zombyWoof': self.ARM,
"imTheSlime": partial(self.selectState, SIGNALS.INSTANT_ARM) 'imTheSlime': self.INSTANT_ARM
} }
def secretCallback(secret, logger): def secretCallback(secret, logger):
@ -88,21 +92,18 @@ class StateMachine:
elif logger: elif logger:
logger.debug('Secret pipe listener received invalid secret') logger.debug('Secret pipe listener received invalid secret')
self.secretListener = PipeListener( self.secretListener = PipeListener(callback=secretCallback, name= 'secret')
callback = secretCallback,
name = 'secret'
)
self.keypadListener = KeypadListener( self.keypadListener = KeypadListener(
stateMachine = self, stateMachine = self,
callbackDisarm = partial(self.selectState, SIGNALS.DISARM), callbackDisarm = self.DISARM,
callbackArm = partial(self.selectState, SIGNALS.ARM), callbackArm = self.ARM,
soundLib = self.soundLib, soundLib = self.soundLib,
passwd = '5918462' passwd = '5918462'
) )
def startTimer(t, sound): def startTimer(t, sound):
self._timer = CountdownTimer(t, partial(self.selectState, SIGNALS.TIMOUT), sound) self._timer = CountdownTimer(t, self.TIMOUT, sound)
def stopTimer(): def stopTimer():
if self._timer.is_alive(): if self._timer.is_alive():