nopasaran.machines.state_machine.StateMachine

class nopasaran.machines.state_machine.StateMachine(state_json, parameters=[], root_state_machine=None)

Bases: object

__init__(state_json, parameters=[], root_state_machine=None)

Initialize the StateMachine.

Args:

state_json (dict): The JSON representation of the state machine. parameters (list, optional): The parameters for the state machine. Defaults to []. root_state_machine (StateMachine, optional): The root state machine. Defaults to None.

Methods

__init__(state_json[, parameters, ...])

Initialize the StateMachine.

add_redirection(event, state)

Add a redirection from an event to a state.

add_transition_actions(next_state_name[, ...])

Add transition actions for the next state.

assign_variables(variables)

Assign variables to the state machine.

execute_action(action)

Execute an action.

get_nested_machine(nested_state_json, parameters)

Get a nested state machine.

get_variable_value(variable_name)

Get the value of a variable.

make_transition(possible_states)

Make a state transition.

set_variable_value(name, new_value)

Set the value of a variable.

start()

Start the state machine and execute actions.

start_sniffer()

Start the sniffer for the state machine.

stop_sniffer()

Stop the sniffer for the state machine.

trigger_event(event)

Trigger an event.

update_sniffer_filter(filter)

Update the filter for the sniffer.

update_sniffer_queue(queue)

Update the queue for the sniffer.

update_state(state)

Update the current state of the state machine.

update_variable_value(variable_name, new_value)

Update the value of a variable.

add_redirection(event, state)

Add a redirection from an event to a state.

Args:

event (str): The event to redirect. state (str): The state to redirect to.

add_transition_actions(next_state_name, assignable=False, state=None)

Add transition actions for the next state.

Args:

next_state_name (str): The name of the next state. assignable (bool, optional): Whether the transition is assignable. Defaults to False. state (dict, optional): The state transition. Defaults to None.

assign_variables(variables)

Assign variables to the state machine.

Args:

variables (dict): The variables to assign.

execute_action(action)

Execute an action.

Args:

action (dict): The action to execute.

get_nested_machine(nested_state_json, parameters)

Get a nested state machine.

Args:

nested_state_json (dict): The JSON representation of the nested state machine. parameters (list): The parameters for the nested state machine.

Returns:

StateMachine: The nested state machine.

get_variable_value(variable_name)

Get the value of a variable.

Args:

variable_name (str): The name of the variable.

Returns:

The value of the variable.

make_transition(possible_states)

Make a state transition.

Args:

possible_states (list): The possible states for the transition.

set_variable_value(name, new_value)

Set the value of a variable.

Args:

name (str): The name of the variable. new_value: The new value for the variable.

start()

Start the state machine and execute actions.

start_sniffer()

Start the sniffer for the state machine.

stop_sniffer()

Stop the sniffer for the state machine.

trigger_event(event)

Trigger an event.

Args:

event (str): The event to trigger.

update_sniffer_filter(filter)

Update the filter for the sniffer.

Args:

filter (str): The new filter.

update_sniffer_queue(queue)

Update the queue for the sniffer.

Args:

queue: The new queue.

update_state(state)

Update the current state of the state machine.

Args:

state (str): The new state.

update_variable_value(variable_name, new_value)

Update the value of a variable.

Args:

variable_name (str): The name of the variable. new_value: The new value for the variable.