shellbot.machines.sequence module¶
-
class
shellbot.machines.sequence.
Sequence
(bot=None, machines=None, **kwargs)[source]¶ Bases:
object
Implements a sequence of multiple machines
This implements one state machine that is actually a combination of multiple sub-machines, ran in sequence. When one sub-machine stops, the next one is activated.
Example:
input_1 = Input( ... ) input_2 = Input( ... ) sequence = Sequence([input_1, input_2]) sequence.start()
In this example, the first machine is started, then when it ends the second machine is triggered.
-
get
(key, default=None)[source]¶ Retrieves the value of one key
Parameters: - key (str) – one attribute of this state machine instance
- default (an type that can be serialized) – default value is the attribute has not been set yet
This function can be used across multiple processes, so that a consistent view of the state machine is provided.
-
is_running
¶ Determines if this machine is runnning
Returns: True or False
-
on_init
(**kwargs)[source]¶ Adds to machine initialisation
This function should be expanded in sub-class, where necessary.
Example:
def on_init(self, prefix='my.machine', **kwargs): ...
-
on_reset
()[source]¶ Adds processing to machine reset
This function should be expanded in sub-class, where necessary.
-
reset
()[source]¶ Resets a state machine before it is restarted
Returns: True if the machine has been actually reset, else False This function moves a state machine back to its initial state. A typical use case is when you have to recycle a state machine multiple times, like in the following example:
if new_cycle(): machine.reset() machine.start()
If the machine is running, calling
reset()
will have no effect and you will get False in return. Therefore, if you have to force a reset, you may have to stop the machine first.Example of forced reset:
machine.stop() machine.reset()
-
run
()[source]¶ Continuously ticks the sequence
This function is looping in the background, and calls the function
step()
at regular intervals.The loop is stopped when the parameter
general.switch
is changed in the context. For example:bot.context.set('general.switch', 'off')
-
set
(key, value)[source]¶ Remembers the value of one key
Parameters: - key (str) – one attribute of this state machine instance
- value (an type that can be serialized) – new value of the attribute
This function can be used across multiple processes, so that a consistent view of the state machine is provided.
-