hololinked.core.state_machine.StateMachine
A finite state machine to constrain property and action execution. Each Thing class can only have one state machine
instantiated in a reserved class-level attribute named state_machine. Other instantiations are not respected.
The state attribute defined as a Thing's property reflects the current state of the state machine and
can be subscribed for state change events. When state_machine is accessed by a Thing instance,
a BoundFSM object is returned.
Source code in hololinked/hololinked/core/state_machine.py
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 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 | |
Attributes
initial_state
class-attribute
instance-attribute
initial state of the machine
machine
class-attribute
instance-attribute
the machine specification with state as key and objects as list
on_enter
class-attribute
instance-attribute
callbacks to execute when a certain state is entered; specified as map with state as keys and callbacks as list
on_exit
class-attribute
instance-attribute
callbacks to execute when certain state is exited; specified as map with state as keys and callbacks as list
push_state_change_event
class-attribute
instance-attribute
if True, when the state changes, an event is pushed with the new state
valid
class-attribute
instance-attribute
valid = Boolean(default=False, readonly=True, fget=lambda self: _valid, doc='internally computed, `True` if states, initial_states and the machine is valid')
internally computed, True if states, initial_states and the machine is valid
Functions
__init__
__init__(states: EnumMeta | list[str] | tuple[str], *, initial_state: StrEnum | str, push_state_change_event: bool = True, on_enter: dict[str, list[Callable] | Callable] = None, on_exit: dict[str, list[Callable] | Callable] = None, **machine: dict[str, Callable | Property]) -> None
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
EnumMeta | list[str] | tuple[str]
|
enumeration of states |
required |
|
StrEnum | str
|
initial state of machine |
required |
|
bool
|
when the state changes, an event is pushed to clients with the new state as the payload |
True
|
|
dict[str, list[Callable] | Callable]
|
callbacks to be invoked when a certain state is entered. It is to be specified as a dictionary with the states being the keys and the list of functions or methods as values. |
None
|
|
dict[str, list[Callable] | Callable]
|
callbacks to be invoked when a certain state is exited. It is to be specified as a dictionary with the states being the keys and the list of functions or methods as values. |
None
|
|
dict[str, Callable | Property]
|
the state machine specification with state as key and list of methods or properties as values.
|
{}
|
Source code in hololinked/hololinked/core/state_machine.py
contains_object
Check if specified object is found in any of the state machine states. Supply unbound method for checking methods, as state machine is specified at class level when the methods are unbound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Property | Callable
|
The unbound method or property |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Source code in hololinked/hololinked/core/state_machine.py
validate
validate the state machine, whether the properties, actions and states are correctly specified
Source code in hololinked/hololinked/core/state_machine.py
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 208 209 210 211 | |