BB.Command.SetState (bb v0.15.0)

View Source

Reusable command handler for transitioning between operational states.

Use this handler to define simple state transition commands without implementing a custom handler. The target state is specified in the handler options.

Usage

commands do
  command :enter_recording do
    handler {BB.Command.SetState, to: :recording}
    allowed_states [:idle]
  end

  command :exit_recording do
    handler {BB.Command.SetState, to: :idle}
    allowed_states [:recording]
  end
end

Then execute:

{:ok, cmd} = MyRobot.enter_recording()
{:ok, :recording} = BB.Command.await(cmd)
BB.Robot.Runtime.state(MyRobot)  # => :recording

Handler Options

  • :to (required) - The target state to transition to. Must be defined in the robot's states section.