Implement trigger history in FSMBase

This commit is contained in:
Kristóf Tóth 2018-07-14 20:44:31 +02:00
parent d98ce58651
commit 77f14df17b

View File

@ -24,6 +24,7 @@ class FSMBase(Machine, CallbackMixin):
def __init__(self, initial=None, accepted_states=None): def __init__(self, initial=None, accepted_states=None):
self.accepted_states = accepted_states or [self.states[-1]] self.accepted_states = accepted_states or [self.states[-1]]
self.trigger_predicates = defaultdict(list) self.trigger_predicates = defaultdict(list)
self.trigger_history = []
Machine.__init__( Machine.__init__(
self, self,
@ -61,5 +62,6 @@ class FSMBase(Machine, CallbackMixin):
if all(predicate_results): if all(predicate_results):
try: try:
self.trigger(trigger) self.trigger(trigger)
self.trigger_history.append(trigger)
except (AttributeError, MachineError): except (AttributeError, MachineError):
LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger) LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger)