betfsm.TickingStateMachine

Bases: TickingState

A StateMachine that calls a callback function before entering a state and/or at each transition.

This statemachine is capable of working together with TickingState:

  • will exit when TICKING outcome is given by one of the substates, but then if it is called again, it will have remembered the state that had the TICKING outcome and start from that state.
  • if returning with any other outcome, will start next time from the start state.

__init__(name, outcomes)

TickintStatemachine is a statemachine that can maintain TickingStates.

Parameters:
  • name (str) –

    (instance) name of the state machine

  • outcomes (List[str]) –

    the allowed outcomes of the state machine, any outcome not specified in transitions will be an outcome of the state machine and should be contained in outcomes (otherwise exception+abort)

accept(visitor)

accepts a visitor to go through all states of an hierarchy

add_state(state, transitions=None)

add_state(state,transitions) adds a state and associates transitions in this state-machine with this state. By default to first state added will be the start state. This can be changed using the method set_start_state.

Parameters:
  • state (TickingState) –

    state to be added, it will be added under its name (i.e. state.name, as defined in TickingState)

  • transitions (Dict[str, str | TickingState], default: None ) –

    A Python Dict that maps outcome of the state to a target (see note below). - a dictionary that maps outcomes of the state to names of a state in this state machine. - As a shortcut/alternative, this can also be a dictionary that maps outcomes to TickingState (in that case TickingState.name is used)

Note
  • The keys of the transitions Dict are outcomes. The values are targets.
  • A target can be a state object or the name of a state.
  • A target can also be an outcome that is listed in the outcomes of the state machine. In that case the state machine will exit with that outcome.
  • A target can be another outcome that the statemachine will try to resolve. This is mostly useful for default transitions (see set_default_transitions). This redirection can even redirect TICKING (for advanced use).
  • a BeTFSM object can only be added as a child once. BeTFSM hierarchy is required to be a tree, not a more general graph.

reset()

Resets the state-machine. Ensures that the next call will start again from the starting state. Calls reset on all the states it contains.

set_default_transitions(transitions={})

Adds default transitions to each state added afterwards. The transitions specified in add_state add to or overwrite these default transitions.

Parameters:
  • transitions (Dict[str, str | TickingState], default: {} ) –

    a dictionary that maps outcomes of the state to other outcomes or another state. See add_state

set_start_state(name)

Explicitly states the starting state. States are specified using their name

Parameters:
  • name (str | TickingState) –

    set the state by which the state machine starts. By default the first state added. Can also be an instance of TickingState descendant, in that case this is the same as name.name