Modules
Machine
¶
Bases: BaseModel
Source code in kiwi_cogs/machine.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 |
|
actions: Optional[Dict[str, Callable]]
instance-attribute
¶
Action side effects for the machine
context: Optional[Dict[str, Any]]
instance-attribute
¶
The contextual information
events: Optional[Union[Dict[str, Event], List[Event]]] = {}
class-attribute
instance-attribute
¶
The events at the root of the machine
guards: Optional[Dict[str, Callable]]
instance-attribute
¶
Possible guards, which are callables
initial: str
instance-attribute
¶
The name of the initial state
initial_state: State
property
¶
Get the initial state of the machine
:returns: The initial state of the machine :rtype: State
logger: Logger = getLogger(__name__)
class-attribute
instance-attribute
¶
The logger for the machine
name: str
instance-attribute
¶
The name for the machine
state: Optional[State]
instance-attribute
¶
The current state for the machine
states: Dict[str, State]
instance-attribute
¶
The possible states for the machine
build_events(value)
¶
Build the events
:param value: The events to be built :type value: dict
:returns: The built events as a dictionary :rtype: dict
Source code in kiwi_cogs/machine.py
79 80 81 82 83 84 85 86 87 88 89 |
|
build_initial_state(values)
¶
Builds the initial state value.
:param values: The values passed to the Machine constructor. :type values: Dict
:return: The updated values. :rtype: Dict
Source code in kiwi_cogs/machine.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
build_states(value, values)
¶
Builds the states from the passed in states object.
:param value: The state configuration dictionary. :type value: dict
:return: The built state objects. :rtype: Dict[str, State]
Source code in kiwi_cogs/machine.py
35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
create(config)
async
classmethod
¶
Creates a new instance of the Machine class.
:param config: The machine configuration dictionary. :type config: dict
:return: The created Machine instance. :rtype: Machine
Source code in kiwi_cogs/machine.py
65 66 67 68 69 70 71 72 73 74 75 76 77 |
|
do_transition(target)
async
¶
Set a state from a target
:param target: The name of the state to transition to :type target: str
Source code in kiwi_cogs/machine.py
177 178 179 180 181 182 183 184 185 186 |
|
event(event)
async
¶
Transitions the machine by executing an event
:param event: The name of the event to trigger :type event: str
:returns: The current state of the machine after the transition :rtype: State
Source code in kiwi_cogs/machine.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
|
on_entry(context)
async
¶
Perform any entry actions for the new state
:param context: The context data for the current state :type context: dict
Source code in kiwi_cogs/machine.py
140 141 142 143 144 145 146 |
|
on_exit(context)
async
¶
Perform any exit actions for the current state
:param context: The context data for the current state :type context: dict
Source code in kiwi_cogs/machine.py
148 149 150 151 152 153 154 |
|
step(state=None)
async
¶
Step through the machine until no more transitions to move through
:param state: The state to start the step process from, defaults to None which will use the current state of the machine :type state: Optional[State], optional
:returns: The final state after all possible transitions have been processed :rtype: State
Source code in kiwi_cogs/machine.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
|
update_config(config)
¶
Updates this instances config with the passed in config.
:param config: The configuration to update the instance with. :type config: dict
Source code in kiwi_cogs/machine.py
91 92 93 94 95 96 97 |
|
update_state(target)
async
¶
Update the current state to the target state
:raises: UnknownTarget - If the target state can not be found
Source code in kiwi_cogs/machine.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
with_context(context)
async
¶
Update the context and step through the machine
:param context: The context to update the machine with :type context: dict
:returns: The final state after all possible transitions have been processed :rtype: State
Source code in kiwi_cogs/machine.py
188 189 190 191 192 193 194 195 196 197 198 |
|
UnknownAction
¶
Bases: Exception
Action could not be found
Source code in kiwi_cogs/exceptions.py
5 6 |
|
UnknownGuard
¶
Bases: Exception
Guard could not be found
Source code in kiwi_cogs/exceptions.py
9 10 |
|
UnknownTarget
¶
Bases: Exception
Target state can not be found
Source code in kiwi_cogs/exceptions.py
1 2 |
|