Add first version of YamlFSM

This commit is contained in:
Kristóf Tóth 2018-07-03 15:14:00 +02:00
parent 7c0e6d49bc
commit 5e4303ac06
3 changed files with 20 additions and 0 deletions

View File

@ -4,3 +4,4 @@
from .event_handler_base import EventHandlerBase, TriggeredEventHandler, BroadcastingEventHandler
from .fsm_base import FSMBase
from .linear_fsm import LinearFSM
from .yaml_fsm import YamlFSM

18
lib/tfw/yaml_fsm.py Normal file
View File

@ -0,0 +1,18 @@
import yaml
from transitions import State
from tfw import FSMBase
class YamlFSM(FSMBase):
def __init__(self, config_file):
self.config = self.parse_config(config_file)
self.states = [State(**state) for state in self.config['states']]
super(YamlFSM, self).__init__()
for transition in self.config['transitions']:
self.machine.add_transition(**transition)
@staticmethod
def parse_config(config_file):
with open(config_file, 'r') as ifile:
return yaml.load(ifile)

View File

@ -3,3 +3,4 @@ pyzmq==17.0.0
transitions==0.6.4
terminado==0.8.1
watchdog==0.8.3
PyYAML==3.12