Rename FSMManager handler -> predicate so it actually makes some sense

This commit is contained in:
Kristóf Tóth 2018-02-26 15:54:10 +01:00
parent 7e8ea0c7ac
commit 78b689f650

View File

@ -41,22 +41,22 @@ class TFWServer:
class FSMManager: class FSMManager:
def __init__(self, fsm): def __init__(self, fsm):
self._fsm = fsm self._fsm = fsm
self.trigger_handlers = defaultdict(list) self.trigger_predicates = defaultdict(list)
@property @property
def fsm(self): def fsm(self):
return self._fsm return self._fsm
def trigger(self, trigger, message): def trigger(self, trigger, message):
if all((handler() for handler in self.trigger_handlers[trigger])): if all((predicate() for predicate in self.trigger_predicates[trigger])):
try: self.fsm.trigger(trigger, message=message) try: self.fsm.trigger(trigger, message=message)
except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger)) except AttributeError: log.debug('FSM failed to execute nonexistent trigger: "{}"'.format(trigger))
def subscribe_handler(self, trigger, handler): def subscribe_predicate(self, trigger, predicate):
self.trigger_handlers[trigger].append(handler) self.trigger_predicates[trigger].append(predicate)
def unsubscribe_handler(self, trigger, handler): def unsubscribe_predicate(self, trigger, predicate):
self.trigger_handlers[trigger].append(handler) self.trigger_predicates[trigger].append(predicate)
class FSMUpdater: class FSMUpdater: