From b7df80120d4be71511e31097b9d3a863fe81070d Mon Sep 17 00:00:00 2001 From: Mario Sarcevic Date: Sun, 23 Jun 2019 12:18:17 +0200 Subject: [PATCH 1/2] Refactor for consistency and readability (use PEP8 style) --- README.md | 4 +- automatabpp/automatabpp.py | 54 ++++++++++++------------ automatabpp/commandqueue/commandqueue.py | 21 +++++---- automatabpp/constants/__init__.py | 6 +-- automatabpp/machine/machine.py | 33 +++++++-------- automatabpp/machines/machines.py | 49 ++++++++++----------- automatabpp/state/state.py | 28 ++++++------ automatabpp/xml/xmlread.py | 9 ++-- docs/FSM.md | 10 ++--- docs/examples/example1.md | 8 ++-- docs/examples/example2.md | 6 +-- docs/examples/example3.md | 4 +- docs/examples/example4.md | 4 +- docs/tutorial.md | 8 ++-- example1.py | 8 ++-- example2.py | 4 +- example3.py | 4 +- example4.py | 8 ++-- 18 files changed, 133 insertions(+), 135 deletions(-) diff --git a/README.md b/README.md index 8f07fb4..31536fb 100644 --- a/README.md +++ b/README.md @@ -49,8 +49,8 @@ def ON_START(*args, **kwargs): def HELLO(*args, **kwargs): print("Hello!") -FSM.OPERATION.start_fsm() # prints "FSM start" -FSM.OPERATION.run_fsm("is_anyone_there") # prints "Hello!" +FSM.OPERATION.start() # prints "FSM start" +FSM.OPERATION.run("is_anyone_there") # prints "Hello!" ``` To learn more please check [the examples at the bottom of the page](#additional-links). diff --git a/automatabpp/automatabpp.py b/automatabpp/automatabpp.py index fe94bc0..a99c7c9 100644 --- a/automatabpp/automatabpp.py +++ b/automatabpp/automatabpp.py @@ -1,15 +1,15 @@ -__all__ = ["BEHAVIOUR", "EXECUTION", "OPERATION", "INTERFACE", "COMPARISONS"] - import logging -automata_bpp_logger = logging.getLogger(__name__) +from functools import wraps -from . machines.machines import Machines -from . xml.xmlread import read_graphml -from . commandqueue.commandqueue import CommandQueue -from . constants import GRAPHS_DIRECTORY, START_COMMAND_NAME, STOP_COMMAND_NAME -from . comparisons.comparisons import COMPARISONS +from .commandqueue.commandqueue import CommandQueue +from .comparisons.comparisons import COMPARISONS +from .constants import START_COMMAND, STOP_COMMAND +from .machines.machines import Machines +from .xml.xmlread import read_graphml -from functools import wraps +__all__ = ["BEHAVIOUR", "EXECUTION", "OPERATION", "INTERFACE", "COMPARISONS", "LOGGER"] + +LOGGER = logging.getLogger(__name__) class BEHAVIOUR: @@ -24,42 +24,42 @@ def load_behaviour_from_graph(graph_file_path: str, machine_name: str): if graph_file_path[-8:] == ".graphml": read_graphml("{}/{}".format(GRAPHS_DIRECTORY, graph_file_path), machine_name) else: - automata_bpp_logger.warning("Unknown format for reading the graph file: {}".format(graph_file_path)) + LOGGER.warning("Unknown format for reading the graph file: {}".format(graph_file_path)) class EXECUTION: @staticmethod def state(func): - current_machine = Machines().GetCurrentDefinedMachine() - if current_machine is not None: - current_machine.SetExecuteStateFunction(func.__name__, func) + machine = Machines().this_machine() + if machine is not None: + machine.set_state_function(func.__name__, func) return func class OPERATION: @staticmethod - def start_fsm(): - Machines().ExecuteCommand(START_COMMAND_NAME) + def start(): + Machines().execute_command(START_COMMAND) @staticmethod - def stop_fsm(): - Machines().ExecuteCommand(STOP_COMMAND_NAME) - Machines().ReturnToStart() - CommandQueue().EmptyAllCommands() + def stop(): + Machines().execute_command(STOP_COMMAND) + Machines().reset_machines() + CommandQueue().clear_all() @staticmethod - def reset_fsm(): - OPERATION.stop_fsm() - OPERATION.start_fsm() + def reset(): + OPERATION.stop() + OPERATION.start() @staticmethod - def run_fsm(cmd=None): + def run(cmd=None): if cmd is None: - Machines().ExecuteAllCommands() + Machines().execute_all() else: - Machines().ExecuteCommand(cmd) + Machines().execute_command(cmd) class INTERFACE: @@ -71,7 +71,9 @@ def wrapper_out(func): def wrapper_in(*args, **kwargs): result = func(*args, **kwargs) if lambda_func(result): - Machines().ExecuteCommand(command) + Machines().execute_command(command) return result + return wrapper_in + return wrapper_out diff --git a/automatabpp/commandqueue/commandqueue.py b/automatabpp/commandqueue/commandqueue.py index 281eaaf..c2ef123 100644 --- a/automatabpp/commandqueue/commandqueue.py +++ b/automatabpp/commandqueue/commandqueue.py @@ -1,4 +1,4 @@ -from automatabpp.automatabpp import automata_bpp_logger +from automatabpp.automatabpp import LOGGER from automatabpp.metaclasses.singleton import Singleton @@ -6,22 +6,21 @@ class CommandQueue(object, metaclass=Singleton): SEPARATOR = "\n" def __init__(self): - self.__list_of_cmds_to_execute = [] + self.__commands = [] def __len__(self): - return len(self.__list_of_cmds_to_execute) + return len(self.__commands) - def GetNextCommand(self): + def get_next(self): if len(self) > 0: - return self.__list_of_cmds_to_execute.pop(0) + return self.__commands.pop(0) return None - def PushCommandsToQueue(self, commands: str): + def push_commands(self, commands: str): for cmd in commands.split(CommandQueue.SEPARATOR): if len(cmd) > 0: - automata_bpp_logger.debug("++++++> {} pushed to CommandQueue <++++++".format(cmd)) - self.__list_of_cmds_to_execute.append(cmd) - - def EmptyAllCommands(self): - self.__list_of_cmds_to_execute.clear() + LOGGER.debug("++++++> {} pushed to CommandQueue <++++++".format(cmd)) + self.__commands.append(cmd) + def clear_all(self): + self.__commands.clear() diff --git a/automatabpp/constants/__init__.py b/automatabpp/constants/__init__.py index a8bd915..e4769c7 100644 --- a/automatabpp/constants/__init__.py +++ b/automatabpp/constants/__init__.py @@ -1,5 +1,5 @@ GRAPHS_DIRECTORY = "graphs" -START_STATE_NAME = "_START_" -START_COMMAND_NAME = "_start_" -STOP_COMMAND_NAME = "_stop_" +START_STATE = "_START_" +START_COMMAND = "_start_" +STOP_COMMAND = "_stop_" diff --git a/automatabpp/machine/machine.py b/automatabpp/machine/machine.py index ddf2baf..49864ba 100644 --- a/automatabpp/machine/machine.py +++ b/automatabpp/machine/machine.py @@ -1,6 +1,6 @@ -from automatabpp.automatabpp import automata_bpp_logger +from automatabpp.automatabpp import LOGGER +from automatabpp.constants import START_STATE from automatabpp.state.state import State -from automatabpp.constants import START_STATE_NAME class Machine(object): @@ -8,31 +8,28 @@ class Machine(object): def __init__(self, machine_name: str): self.machine_name = machine_name self.states = dict() - self.curr_state = self.GetStateWithName(START_STATE_NAME) + self.curr_state = self.get_state_by_name(START_STATE) - def GetActiveState(self): - return self.curr_state - - def GetStateWithName(self, state_name: str): + def get_state_by_name(self, state_name: str): if state_name in self.states.keys(): return self.states[state_name] self.states[state_name] = State(state_name, self.machine_name) return self.states[state_name] - def AddTransition(self, st_before: str, command: str, st_after: str): - self.GetStateWithName(st_before).SetTransition(command, st_after) + def add_transition(self, state_before: str, command: str, state_after: str): + self.get_state_by_name(state_before).set_transition(command, state_after) - def SetExecuteStateFunction(self, state_name: str, callback: callable): - self.GetStateWithName(state_name).SetExecuteStateFunction(callback) + def set_state_function(self, state_name: str, callback: callable): + self.get_state_by_name(state_name).set_state_function(callback) - def ExecuteTransition(self, command: str): - st_after_name = self.curr_state.GetNextStateWithTransition(command) + def transition(self, command: str): + st_after_name = self.curr_state.transition_to_next(command) if st_after_name is not None: - automata_bpp_logger.debug("{}: state change {}->{}".format(self.machine_name, self.curr_state.GetName(), st_after_name)) - self.curr_state = self.GetStateWithName(st_after_name) - self.curr_state.ExecuteState(command) + LOGGER.debug("{}: state change {}->{}".format(self.machine_name, self.curr_state.get_name(), st_after_name)) + self.curr_state = self.get_state_by_name(st_after_name) + self.curr_state.execute_state(command) return True return False - def ReturnToStart(self): - self.curr_state = self.GetStateWithName(START_STATE_NAME) + def reset_to_start(self): + self.curr_state = self.get_state_by_name(START_STATE) diff --git a/automatabpp/machines/machines.py b/automatabpp/machines/machines.py index e4a2caf..8f06939 100644 --- a/automatabpp/machines/machines.py +++ b/automatabpp/machines/machines.py @@ -1,42 +1,39 @@ -from automatabpp.automatabpp import automata_bpp_logger -from automatabpp.metaclasses.singleton import Singleton -from automatabpp.machine.machine import Machine +from automatabpp.automatabpp import LOGGER from automatabpp.commandqueue.commandqueue import CommandQueue +from automatabpp.machine.machine import Machine +from automatabpp.metaclasses.singleton import Singleton class Machines(object, metaclass=Singleton): def __init__(self): - self.__list_of_machines = [] - self.curr_machine_to_define = None + self.machines = [] + self.machine = None - def AddNewMachine(self, machine_name: str): - self.curr_machine_to_define = Machine(machine_name) - self.__list_of_machines.append(self.curr_machine_to_define) - return self.curr_machine_to_define + def add_new_machine(self, machine_name: str): + self.machine = Machine(machine_name) + self.machines.append(self.machine) + return self.machine - def ExecuteNextCommand(self): # Some patterns could use this - next_command = CommandQueue().GetNextCommand() + def execute_next(self): # Some patterns could use this + next_command = CommandQueue().get_next() if next_command is not None: - self.ExecuteCommand(next_command) + self.execute_command(next_command) return True return False - def ExecuteAllCommands(self): # Should be used as default + def execute_all(self): # Should be used as default while len(CommandQueue()) > 0: - self.ExecuteNextCommand() - - def ExecuteCommand(self, command: str): # Not recommended if states can execute commands - automata_bpp_logger.debug("Executing command [{}]".format(command)) - for machine in self.__list_of_machines: - machine.ExecuteTransition(command) + self.execute_next() - def _AddTransitionToCurrDefined(self, st_before: str, command: str, st_after: str): - self.curr_machine_to_define.AddTransition(st_before, command, st_after) + def execute_command(self, command: str): # Not recommended if states can execute commands + LOGGER.debug("Executing command [{}]".format(command)) + for machine in self.machines: + machine.transition(command) - def GetCurrentDefinedMachine(self): - return self.curr_machine_to_define + def this_machine(self): + return self.machine - def ReturnToStart(self): - for machine in self.__list_of_machines: - machine.ReturnToStart() + def reset_machines(self): + for machine in self.machines: + machine.reset_to_start() diff --git a/automatabpp/state/state.py b/automatabpp/state/state.py index 4d3ee63..c2a532e 100644 --- a/automatabpp/state/state.py +++ b/automatabpp/state/state.py @@ -1,38 +1,38 @@ -from automatabpp.automatabpp import automata_bpp_logger +from automatabpp.automatabpp import LOGGER from automatabpp.commandqueue.commandqueue import CommandQueue class State(object): def __not_defined(self, **_): - automata_bpp_logger.debug("Machine:State [{}:{}] Execution not defined".format(self.machine_name, self.state_name)) + LOGGER.debug("Machine:State [{}:{}] Execution not defined".format(self.machine_name, self.name)) def __init__(self, state_name: str, machine_name: str): self.machine_name = machine_name - self.state_name = state_name + self.name = state_name self.callback = self.__not_defined self.transitions = dict() - self.after_execution_commands = list() + self.post_commands = list() - def GetName(self): - return self.state_name + def get_name(self): + return self.name - def SetExecuteStateFunction(self, callback: callable): + def set_callback(self, callback: callable): self.callback = callback - def SetTransition(self, command: str, next_state_name): + def set_transition(self, command: str, next_state_name): self.transitions[command] = next_state_name - def AddCommandToCallAfterExecution(self, cmd: str): + def add_post_command(self, cmd: str): if len(cmd) > 0: - self.after_execution_commands.append(cmd) + self.post_commands.append(cmd) - def ExecuteState(self, command): + def execute_state(self, command): self.callback(command=command) - for cmd in self.after_execution_commands: - CommandQueue().PushCommandsToQueue(cmd) + for cmd in self.post_commands: + CommandQueue().push_commands(cmd) - def GetNextStateWithTransition(self, command): + def transition_to_next(self, command): if command in self.transitions.keys(): return self.transitions[command] return None diff --git a/automatabpp/xml/xmlread.py b/automatabpp/xml/xmlread.py index 71795cf..3431c3a 100644 --- a/automatabpp/xml/xmlread.py +++ b/automatabpp/xml/xmlread.py @@ -1,6 +1,7 @@ import xml.etree.ElementTree as ET -from automatabpp.machines.machines import Machines + from automatabpp.commandqueue.commandqueue import CommandQueue +from automatabpp.machines.machines import Machines def read_graphml(graphml_path: str, machine_name: str): @@ -40,11 +41,11 @@ def __init__(self, _edge): edges = [GraphEdge(edge) for edge in root.findall("ns0:graph/ns0:edge", read_graphml.ns)] nodes = [GraphNode(node) for node in root.findall("ns0:graph/ns0:node", read_graphml.ns)] node_map = dict() - new_machine = Machines().AddNewMachine(machine_name) + new_machine = Machines().add_new_machine(machine_name) for node in nodes: node_map[node.id] = node.name for transition in node.transitions_after.split(CommandQueue.SEPARATOR): - new_machine.GetStateWithName(node.name).AddCommandToCallAfterExecution(transition) + new_machine.get_state_by_name(node.name).add_post_command(transition) for edge in edges: for transition_name in edge.name.split(): - new_machine.AddTransition(node_map[edge.source], transition_name, node_map[edge.target]) + new_machine.add_transition(node_map[edge.source], transition_name, node_map[edge.target]) diff --git a/docs/FSM.md b/docs/FSM.md index 3fa5e8e..bf94a0a 100644 --- a/docs/FSM.md +++ b/docs/FSM.md @@ -12,16 +12,16 @@ Once we `import automatabpp` into our python script we can use the following 4 c Operation is a class that only executes the global operations on the FSMs. ```python -OPERATION.start_fsm() # Starts the FSMs by sending the '_start_' command to all the machines +OPERATION.start() # Starts the FSMs by sending the '_start_' command to all the machines -OPERATION.stop_fsm() # Stops all the FSMs by sending the '_stop_' command to all the machines, +.OPERATIONstop() # Stops all the FSMs by sending the '_stop_' command to all the machines, # reseting them to the default '_START_' state and emptying the machine commands stack. -OPERATION.reset_fsm() # Stops and starts the FSMs +.rOPERATIONeset() # Stops and starts the FSMs -OPERATION.run_fsm() # Runs all the commands in the CommandQueue until the queue is empty. +.ruOPERATIONn() # Runs all the commands in the CommandQueue until the queue is empty. -OPERATION.run_fsm(cmd) # Runs only the cmd on all machines now without running the rest of the queue. +.runOPERATION(cmd) # Runs only the cmd on all machines now without running the rest of the queue. ``` ### BEHAVIOUR diff --git a/docs/examples/example1.md b/docs/examples/example1.md index 7cbedb2..5730a93 100644 --- a/docs/examples/example1.md +++ b/docs/examples/example1.md @@ -44,8 +44,8 @@ Let's see how this is implemented in the [example1.py][pycode] script. ```python def test_email(): for char in email_to_test: - OPERATION.run_fsm(char) - OPERATION.stop_fsm() + OPERATION.run(char) + OPERATION.stop() ``` What this means is we will take one by one character from the e-mail and run it through our machine. At the very end we will send the `_stop_` command to let the automatabpp know we're done. @@ -65,14 +65,14 @@ Let's see how this is implemented in the [example1.py][pycode] script. - Let's run the machine and check our first e-mail address: ```python - OPERATION.start_fsm() + OPERATION.start() email_to_test = "a_valid@email.example" test_email() ``` - Once we're done we can restart the machine since it is currently in __EMAIL__ state and check another e-mail address: ```python - OPERATION.reset_fsm() + OPERATION.reset() email_to_test = "an._invalid@email@example-" test_email() diff --git a/docs/examples/example2.md b/docs/examples/example2.md index 49b1dab..7c1c0fb 100644 --- a/docs/examples/example2.md +++ b/docs/examples/example2.md @@ -74,10 +74,10 @@ Let's see how this is implemented in the [example2.py][pycode] script. - All that's left is to run the machine: ```python - OPERATION.start_fsm() - OPERATION.run_fsm() + OPERATION.start() + OPERATION.run() ``` - One thing to note here is that the `OPERATION.run_fsm()` is executed here without any argument. + One thing to note here is that the `OPERATION.run()` is executed here without any argument. That means it will run all the commands in the `CommandQueue` until the queue is empty. Run the code and see what you get. diff --git a/docs/examples/example3.md b/docs/examples/example3.md index 3910584..80cc664 100644 --- a/docs/examples/example3.md +++ b/docs/examples/example3.md @@ -58,14 +58,14 @@ Let's see how this is implemented in the [example3.py][pycode] script. - Start the machine, run the bytecode through it and every 456 characters print a new line: ```python - OPERATION.start_fsm() + OPERATION.start() example = "Man is distinguished, not only by his reason, but by this singular passion from other animals, " \ "which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable " \ "generation of knowledge, exceeds the short vehemence of any carnal pleasure." for i, char in enumerate(text_to_bits(example)): - OPERATION.run_fsm(char) + OPERATION.run(char) if i > 0 and i % (8*57) == 0: print() ``` diff --git a/docs/examples/example4.md b/docs/examples/example4.md index da40345..df9cf40 100644 --- a/docs/examples/example4.md +++ b/docs/examples/example4.md @@ -158,13 +158,13 @@ You can check the code in the [example4.py][pycode] script. For example: every time we call the `simulate_temperature_reading` function and its return value is in between 1 and 50 the command `temp_normal` will be added to the `CommandQueue` for later execution. - Only thing left to do is to run the automatabpp and simulate reading values: ```python - OPERATION.start_fsm() + OPERATION.start() for i in range(100): volt = round(simulate_battery_voltage_reading(i), 2) # simulate reading the voltage sensor temp = round(simulate_temperature_reading(i), 2) # simulate reading the temperature sensor print("\t\t|\t{}V\t|\t{}°C".format(volt, temp)) - OPERATION.run_fsm() # run commands left in the CommandQueue + OPERATION.run() # run commands left in the CommandQueue time.sleep(2) ``` diff --git a/docs/tutorial.md b/docs/tutorial.md index 8936004..67e88bc 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -79,11 +79,11 @@ Now we are ready to start coding. - We are done with definitions so we can now start our code: ```python - FSM.OPERATION.start_fsm() + FSM.OPERATION.start() ``` This piece of code actually calls the `_start_` command to be executed on all machines. Additionaly we can call the `state_change` command as well. ```python - FSM.OPERATION.run_fsm("state_change") + FSM.OPERATION.run("state_change") ``` If we run our code we should see the following in the console: @@ -109,8 +109,8 @@ def STATE_2(**_): print("Executing STATE_2") -FSM.OPERATION.start_fsm() -FSM.OPERATION.run_fsm("state_change") +FSM.OPERATION.start() +FSM.OPERATION.run("state_change") ``` ### Other diff --git a/example1.py b/example1.py index 16074d4..f44d4a2 100644 --- a/example1.py +++ b/example1.py @@ -5,8 +5,8 @@ def test_email(): for char in email_to_test: - OPERATION.run_fsm(char) - OPERATION.stop_fsm() + OPERATION.run(char) + OPERATION.stop() BEHAVIOUR.load_behaviour_from_graph("email/email.graphml", "E-Mail validation machine") @@ -25,12 +25,12 @@ def EMAIL(**_): # ............................................................................... # ---------- DEFINITIONS COMPLETE - RUNNING THE PROGRAM ------------------------- # ............................................................................... -OPERATION.start_fsm() +OPERATION.start() email_to_test = "a_valid@email.example" test_email() -OPERATION.reset_fsm() +OPERATION.reset() email_to_test = "an._invalid@email@example-" test_email() diff --git a/example2.py b/example2.py index d11e556..a07ea42 100644 --- a/example2.py +++ b/example2.py @@ -36,5 +36,5 @@ def STRONGER(**_): # ............................................................................... # ---------- DEFINITIONS COMPLETE - RUNNING THE PROGRAM ------------------------- # ............................................................................... -OPERATION.start_fsm() -OPERATION.run_fsm() +OPERATION.start() +OPERATION.run() diff --git a/example3.py b/example3.py index ce30ff6..dfdf9c1 100644 --- a/example3.py +++ b/example3.py @@ -22,13 +22,13 @@ def created(**_): # ............................................................................... # ---------- DEFINITIONS COMPLETE - RUNNING THE PROGRAM ------------------------- # ............................................................................... -OPERATION.start_fsm() +OPERATION.start() example = "Man is distinguished, not only by his reason, but by this singular passion from other animals, " \ "which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable " \ "generation of knowledge, exceeds the short vehemence of any carnal pleasure." for i, char in enumerate(text_to_bits(example)): - OPERATION.run_fsm(char) + OPERATION.run(char) if i > 0 and i % (8*57) == 0: print() diff --git a/example4.py b/example4.py index 615a798..598cf84 100644 --- a/example4.py +++ b/example4.py @@ -1,5 +1,7 @@ +import math +import time + from automatabpp import * -import math, time class LED: @@ -64,12 +66,12 @@ def simulate_temperature_reading(num): # ............................................................................... # ---------- DEFINITIONS COMPLETE - RUNNING THE PROGRAM ------------------------- # ............................................................................... -OPERATION.start_fsm() +OPERATION.start() for i in range(100): volt = round(simulate_battery_voltage_reading(i), 2) temp = round(simulate_temperature_reading(i), 2) print("\t\t|\t{}V\t|\t{}°C".format(volt, temp)) - OPERATION.run_fsm() + OPERATION.run() time.sleep(2) From 020446098dba2034686445b4d5ef8a689d4c2514 Mon Sep 17 00:00:00 2001 From: Grgo Mariani Date: Sun, 23 Jun 2019 14:56:33 +0200 Subject: [PATCH 2/2] Fix some issues --- automatabpp/automatabpp.py | 6 ++++-- automatabpp/machine/machine.py | 2 +- docs/FSM.md | 8 ++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/automatabpp/automatabpp.py b/automatabpp/automatabpp.py index a99c7c9..0d7b68f 100644 --- a/automatabpp/automatabpp.py +++ b/automatabpp/automatabpp.py @@ -1,15 +1,17 @@ import logging from functools import wraps +LOGGER = logging.getLogger(__name__) + from .commandqueue.commandqueue import CommandQueue from .comparisons.comparisons import COMPARISONS -from .constants import START_COMMAND, STOP_COMMAND +from .constants import START_COMMAND, STOP_COMMAND, GRAPHS_DIRECTORY from .machines.machines import Machines from .xml.xmlread import read_graphml __all__ = ["BEHAVIOUR", "EXECUTION", "OPERATION", "INTERFACE", "COMPARISONS", "LOGGER"] -LOGGER = logging.getLogger(__name__) + class BEHAVIOUR: diff --git a/automatabpp/machine/machine.py b/automatabpp/machine/machine.py index 49864ba..9ac1451 100644 --- a/automatabpp/machine/machine.py +++ b/automatabpp/machine/machine.py @@ -20,7 +20,7 @@ def add_transition(self, state_before: str, command: str, state_after: str): self.get_state_by_name(state_before).set_transition(command, state_after) def set_state_function(self, state_name: str, callback: callable): - self.get_state_by_name(state_name).set_state_function(callback) + self.get_state_by_name(state_name).set_callback(callback) def transition(self, command: str): st_after_name = self.curr_state.transition_to_next(command) diff --git a/docs/FSM.md b/docs/FSM.md index bf94a0a..b9a6c6d 100644 --- a/docs/FSM.md +++ b/docs/FSM.md @@ -14,14 +14,14 @@ Operation is a class that only executes the global operations on the FSMs. ```python OPERATION.start() # Starts the FSMs by sending the '_start_' command to all the machines -.OPERATIONstop() # Stops all the FSMs by sending the '_stop_' command to all the machines, +OPERATION.stop() # Stops all the FSMs by sending the '_stop_' command to all the machines, # reseting them to the default '_START_' state and emptying the machine commands stack. -.rOPERATIONeset() # Stops and starts the FSMs +OPERATION.reset() # Stops and starts the FSMs -.ruOPERATIONn() # Runs all the commands in the CommandQueue until the queue is empty. +OPERATION.run() # Runs all the commands in the CommandQueue until the queue is empty. -.runOPERATION(cmd) # Runs only the cmd on all machines now without running the rest of the queue. +OPERATION.run(cmd) # Runs only the cmd on all machines now without running the rest of the queue. ``` ### BEHAVIOUR