Fix fsm.update messages being thiggered without a state change

This commit is contained in:
Kristóf Tóth 2019-12-19 13:58:48 +01:00
parent 269cab691e
commit c8d4080ef5

View File

@ -1,6 +1,7 @@
import logging import logging
from collections import defaultdict from collections import defaultdict
from datetime import datetime from datetime import datetime
from contextlib import suppress
from transitions import Machine, MachineError from transitions import Machine, MachineError
@ -62,14 +63,12 @@ class FSMBase(Machine, CallbackMixin):
) )
if all(predicate_results): if all(predicate_results):
try: with suppress(AttributeError, MachineError):
from_state = self.state from_state = self.state
self.trigger(trigger) if self.trigger(trigger):
self.update_event_log(from_state, trigger) self.update_event_log(from_state, trigger)
return True return True
except (AttributeError, MachineError):
LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger) LOG.debug('FSM failed to execute nonexistent trigger: "%s"', trigger)
return False
def update_event_log(self, from_state, trigger): def update_event_log(self, from_state, trigger):
self.event_log.append({ self.event_log.append({