radloggerpy.common.state_machine module

class radloggerpy.common.state_machine.StateMachine(transitions: Dict[Enum, Set[Enum]], states: Enum = None)[source]

Bases: object

Abstract class to provide a state machine to any object

POSSIBLE_STATES: Enum | None = None

Set to a enum that has an item for all desired possible states the initial value of this variable is the initial state.

Super classes implementing StateMachine should consider overriding this variable.

_U

Transition dictionary structure type

alias of Dict[Enum, Set[Enum]]

_abc_impl = <_abc._abc_data object>
_sclass: Type[Enum]

Enum class used for states

_state: Enum

Internal state object to maintain the current state

_verify_transitions()[source]

Iterate the TRANSITIONS dictionary and validate its completeness

get_state()[source]
reset_state()[source]

Reset state to the initial state

transition(state: Enum)[source]

Transition from the current state to a new desired state

Parameters:

state – The new desired state

Raises:

RuntimeWarning – This warning is raised when the new desired state requires an illegal transition

transitions: Dict[Enum, Set[Enum]] = {}

Dictionary with sets as values were the key indicates the current state and the elements in the set describe valid transitions.

Super classes should not override this variable and instead rely on super().__init__(transitions). This ensures that the structure of transitions is valid.