Improve YamlFSM initialization logic

This commit is contained in:
Kristóf Tóth 2018-07-06 12:27:26 +01:00
parent c7ee97f0c6
commit 7f583d8d1f

View File

@ -11,10 +11,8 @@ from tfw import FSMBase
class YamlFSM(FSMBase): class YamlFSM(FSMBase):
def __init__(self, config_file): def __init__(self, config_file):
self.config = self.parse_config(config_file) self.config = self.parse_config(config_file)
self.for_config_states_and_transitions_do(self.patch_config_callbacks)
self.setup_states() self.setup_states()
super().__init__() # FSMBase.__init__() requires states super().__init__() # FSMBase.__init__() requires states
self.for_config_states_and_transitions_do(self.subscribe_and_remove_predicates)
self.setup_transitions() self.setup_transitions()
@staticmethod @staticmethod
@ -23,9 +21,11 @@ class YamlFSM(FSMBase):
return yaml.safe_load(ifile) return yaml.safe_load(ifile)
def setup_states(self): def setup_states(self):
self.for_config_states_and_transitions_do(self.patch_config_callbacks)
self.states = [State(**state) for state in self.config['states']] self.states = [State(**state) for state in self.config['states']]
def setup_transitions(self): def setup_transitions(self):
self.for_config_states_and_transitions_do(self.subscribe_and_remove_predicates)
for transition in self.config['transitions']: for transition in self.config['transitions']:
self.add_transition(**transition) self.add_transition(**transition)