Power sensor API | Component APIs
Power sensor API
The power sensor API allows you to give commands to your power sensor components for getting measurements of voltage, current, and power consumption.
The power sensor component supports the following methods:
| Method Name | Description |
|---|---|
GetVoltage |
Return the voltage reading of a specified device and whether it is AC or DC. |
GetCurrent |
Return the current of a specified device and whether it is AC or DC. |
GetPower |
Return the power reading in watts. |
GetReadings |
Get the measurements or readings that this power sensor provides. |
Reconfigure |
Reconfigure this resource. |
DoCommand |
Execute model-specific commands that are not otherwise defined by the component API. |
GetResourceName |
Get the ResourceName for this power sensor. |
Close |
Safely shut down the resource and prevent further use. |
API
GetVoltage
Return the voltage reading of a specified device and whether it is AC or DC.
Parameters:
extra(Mapping[ str, Any]) (optional): Extra options to pass to the underlying RPC call.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Tuple[ float, bool]): A float representing the voltage reading in V. A bool indicating whether the voltage is AC (true) or DC (false).
Example:
For more information, see the Python SDK Docs.
GetCurrent
Return the current of a specified device and whether it is AC or DC.
Parameters:
Returns:
- (Tuple[ float, bool]): A tuple which includes a float representing the current reading in amps, and a bool indicating whether the current is AC (true) or DC (false).
Example:
For more information, see the Python SDK Docs.
GetPower
Return the power reading in watts.
Parameters:
Returns:
- ( float): The power reading in watts.
Example:
For more information, see the Python SDK Docs.
GetReadings
Get the measurements or readings that this power sensor provides. If a sensor is not configured to have a measurement or fails to read a piece of data, it will not appear in the readings dictionary.
Parameters:
Returns:
- (Mapping[ str, viam.utils.SensorReading]): The readings for the PowerSensor. Can be of any type. Includes voltage in volts (float), current in amperes (float), is_ac (bool), and power in watts (float).
Example:
For more information, see the Python SDK Docs.
Reconfigure
Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.
Parameters:
ctx(Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.deps(Dependencies): The resource dependencies.conf(Config): The resource configuration.
Returns:
- (error): An error, if one occurred.
For more information, see the Go 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 power sensor and want to add features that have no corresponding built-in API method, you can implement them with DoCommand.
Parameters:
command(Mapping[ str, ValueTypes]) (required): The command to execute.timeout( float) (optional): An option to set how long to wait (in seconds) before calling a time-out and closing the underlying RPC call.
Returns:
- (Mapping[ str, viam.utils.ValueTypes]): Result of the executed command.
Raises:
- (NotImplementedError): Raised if the Resource does not support arbitrary commands.
Example:
For more information, see the Python SDK Docs.
GetResourceName
Get the ResourceName for this power sensor.
Parameters:
name( str) (required): The name of the Resource.
Returns:
- ( viam.proto.common.ResourceName): The ResourceName of this Resource.
Example:
For more information, see the Python SDK Docs.
Close
Safely shut down the resource and prevent further use.
Parameters:
- None.
Returns:
- None.
Example:
For more information, see the Python SDK Docs.