Skip to content

Component Instance CLI Utils

motion clear

To easily clear a component instance, you can use the CLI command motion clear. If you type motion clear --help, you will see the following:

$ motion clear --help
Usage: motion clear [OPTIONS] INSTANCE

  Clears the state and cached results for a component instance.

  Args:     instance (str): Instance name of the component to clear.
  In the form `componentname__instancename`.

Options:
  --help  Show this message and exit.

  Example usage: motion clear MyComponent__myinstance

motion inspect

To easily view the state stored for a component instance, you can use the CLI command motion inspect. If you type motion inspect --help, you will see the following:

$ motion inspect --help
Usage: motion inspect [OPTIONS] INSTANCE

  Prints the saved state for a component instance. Does not apply any
  loadState() transformations.

  Args:     instance (str): Instance name of the component to clear.
  In the form `componentname__instancename`.

Options:
  --help  Show this message and exit.

  Example usage: motion inspect MyComponent__myinstance

Python Documentation

clear_instance(instance_name: str) -> bool

Clears the state and cached results associated with a component instance.

Usage:

from motion import clear_instance

clear_instance("Counter__default")

Parameters:

Name Type Description Default
instance_name str

Instance name of the component to clear. In the form componentname__instanceid.

required

Raises:

Type Description
ValueError

If the instance name is not in the form componentname__instanceid.

Returns:

Name Type Description
bool bool

True if the instance existed, False otherwise.

inspect_state(instance_name: str) -> Optional[State]

Returns the state of a component instance.

Usage:

from motion import inspect_state

inspect_state("Counter__default")

Parameters:

Name Type Description Default
instance_name str

Instance name of the component to inspect. In the form componentname__instanceid.

required

Raises:

Type Description
ValueError

If the instance name is not in the form componentname__instanceid or if the instance does not exist.

Returns:

Name Type Description
State Optional[State]

The state of the component instance.