State Machine Manager API¶
The StateMachineManager acts as a registry for all State Machines running in the application. It allows for dynamic addition/removal of machines and provides access to their configuration.
automation.managers.state_machine.StateMachineManager()Manages the lifecycle and execution configuration of State Machines.
It maintains a registry of all active machines, their execution intervals, and threading modes (sync/async).
get_queue(self)Retrieves the internal queue used for tag updates related to state machines.
append_machine(self, machine)Registers a new state machine.
Parameters:
- machine (StateMachine): The state machine instance.
get_machines(self)Retrieves the list of all registered state machines.
Returns:
- list: List of tuples [(machine, interval, mode), ...].
serialize_machines(self)Serializes all registered machines to a list of dictionaries.
Returns:
- list[dict]: Serialized machine data.
get_machine(self, name)Retrieves a state machine by its name.
Parameters:
- name (StringType): The name of the machine.
Returns:
- StateMachine: The machine instance if found.
drop(self, name)Removes a state machine from the manager.
Parameters:
- name (str): The name of the machine to remove.
Returns:
- tuple: The removed (machine, interval, mode) tuple.
unsubscribe_tag(self, tag)Unsubscribes a tag from all state machines.
If a DAQ machine has no more subscribed tags, it is removed.
Parameters:
- tag (Tag): The tag to unsubscribe.
Returns:
- tuple: The removed machine tuple if a DAQ machine was dropped.
summary(self)Generates a summary of registered state machines.
Returns:
- dict: {length: int, state_machines: list[str]}
exist_machines(self)Checks if there are any registered state machines.
Returns:
- bool: True if at least one machine exists.