Switch API | Component APIs

Switch API

The switch API allows you to give commands to your switch components for reading the state of a physical switch that has multiple discrete positions. A simple switch has two positions, and a knob could have any number of positions.

The switch component supports the following methods:

Method Name Description viam-micro-server Support
SetPosition Set the position of the switch.
GetPosition Return the current position of the switch.
GetNumberOfPositions Return the number of valid positions for this switch.
DoCommand Execute model-specific commands that are not otherwise defined by the component API.
GetResourceName Get the ResourceName for this servo.
Close Safely shut down the resource and prevent further use.

API

SetPosition

Set the position of the switch. Position must be within the valid range for the switch type. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GetPosition

Return the current position of the switch. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

GetNumberOfPositions

Return the number of valid positions for this switch. Supported by viam-micro-server.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

DoCommand

Execute model-specific commands that are not otherwise defined by the component API. Most models do not implement DoCommand. Any available model-specific commands should be covered in the model’s documentation. If you are implementing your own switch and want to add features that have no corresponding built-in API method, you can implement them with DoCommand. Supported by viam-micro-server.

Parameters:

Returns:

Raises:

Example:


For more information, see the Python SDK Docs.

GetResourceName

Get the ResourceName for this servo.

Parameters:

Returns:

Example:


For more information, see the Python SDK Docs.

Close

Safely shut down the resource and prevent further use.

Parameters:

Returns:

Example: