viam.components.component_base

Module Contents

Classes

ComponentBase

Base component.

class viam.components.component_base.ComponentBase(name: str)[source]

Base component. All components must inherit from this class.

SUBTYPE :ClassVar[viam.resource.types.Subtype]
name :str
classmethod get_resource_name(name: str) viam.proto.common.ResourceName[source]

Get the ResourceName for this component type with the given name

Parameters

name (str) – The name of the Component

classmethod from_robot(robot: viam.robot.client.RobotClient, name: str) typing_extensions.Self[source]

Get the component named name from the provided robot.

Parameters
  • robot (RobotClient) – The robot

  • name (str) – The name of the component

Returns

The component, if it exists on the robot

Return type

Self

get_operation(kwargs: Mapping[str, Any]) viam.operations.Operation[source]

Get the Operation associated with the currently running function.

When writing custom components, you should get the Operation by calling this function and check to see if it’s cancelled. If the Operation is cancelled, then you can perform any necessary (terminating long running tasks, cleaning up connections, etc. ).

Parameters

kwargs (Mapping[str, Any]) – The kwargs object containing the operation

Returns

The operation associated with this function

Return type

Operation

abstract async do_command(command: Dict[str, Any], *, timeout: Optional[float] = None, **kwargs) Dict[str, Any][source]

Send/Receive arbitrary commands

Parameters

command (Dict[str, Any]) – The command to execute

Raises

NotImplementedError – Raised if the component does not support arbitrary commands

Returns

Result of the executed command

Return type

Dict[str, Any]