# Power sensor API

The power sensor API allows you to give commands to your [power sensor components](https://docs.viam.com/reference/components/power-sensor/) for getting measurements of voltage, current, and power consumption.

The power sensor component supports the following methods:

| Method Name | Description |
| --- | --- |
| [`GetVoltage`](https://docs.viam.com/reference/apis/components/power-sensor/#getvoltage) | Return the voltage reading of a specified device and whether it is AC or DC. |
| [`GetCurrent`](https://docs.viam.com/reference/apis/components/power-sensor/#getcurrent) | Return the current of a specified device and whether it is AC or DC. |
| [`GetPower`](https://docs.viam.com/reference/apis/components/power-sensor/#getpower) | Return the power reading in watts. |
| [`GetReadings`](https://docs.viam.com/reference/apis/components/power-sensor/#getreadings) | Get the measurements or readings that this power sensor provides. |
| [`Reconfigure`](https://docs.viam.com/reference/apis/components/power-sensor/#reconfigure) | Reconfigure this resource. |
| [`DoCommand`](https://docs.viam.com/reference/apis/components/power-sensor/#docommand) | Execute model-specific commands that are not otherwise defined by the component API. |
| [`GetResourceName`](https://docs.viam.com/reference/apis/components/power-sensor/#getresourcename) | Get the `ResourceName` for this power sensor. |
| [`Close`](https://docs.viam.com/reference/apis/components/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.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-1-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-1-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-1-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-1-3)

**Parameters:**

- `extra` (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), Any]) (optional): Extra options to pass to the underlying RPC call.
- `timeout` ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (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](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex), [bool](https://docs.python.org/3/library/stdtypes.html#boolean-type-bool)]): A float representing the voltage reading in V. A bool indicating whether the voltage is AC (true) or DC (false).

**Example:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.get_voltage).

### GetCurrent

Return the current of a specified device and whether it is AC or DC.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-2-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-2-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-2-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-2-3)

**Parameters:**

**Returns:**

- (Tuple[ [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex), [bool](https://docs.python.org/3/library/stdtypes.html#boolean-type-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:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.get_current).

### GetPower

Return the power reading in watts.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-3-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-3-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-3-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-3-3)

**Parameters:**

**Returns:**

- ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)): The power reading in watts.

**Example:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.get_power).

### 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.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-4-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-4-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-4-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-4-3)

**Parameters:**

**Returns:**

- (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-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:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.get_readings).

### Reconfigure

Reconfigure this resource. Reconfigure must reconfigure the resource atomically and in place.

- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-5-0)

**Parameters:**

- `ctx` [(Context)](https://pkg.go.dev/context#Context): A Context carries a deadline, a cancellation signal, and other values across API boundaries.
- `deps` [(Dependencies)](https://pkg.go.dev/go.viam.com/rdk/resource#Dependencies): The resource dependencies.
- `conf` [(Config)](https://pkg.go.dev/go.viam.com/rdk/resource#Config): The resource configuration.

**Returns:**

- [(error)](https://pkg.go.dev/builtin#error): An error, if one occurred.

For more information, see the [Go SDK Docs](https://pkg.go.dev/go.viam.com/rdk/resource#Resource).

### 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`](https://docs.viam.com/reference/sdks/docommand/).

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-6-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-6-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-6-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-6-3)

**Parameters:**

- `command` (Mapping[ [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), ValueTypes]) (required): The command to execute.
- `timeout` ( [float](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex)) (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](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str), viam.utils.ValueTypes]): Result of the executed command.

**Raises:**

- (NotImplementedError): Raised if the Resource does not support arbitrary commands.

**Example:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.do_command).

### GetResourceName

Get the `ResourceName` for this power sensor.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-7-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-7-1)
- [TypeScript](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-7-2)
- [Flutter](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-7-3)

**Parameters:**

- `name` ( [str](https://docs.python.org/3/library/stdtypes.html#text-sequence-type-str)) (required): The name of the Resource.

**Returns:**

- ( [viam.proto.common.ResourceName](https://python.viam.dev/autoapi/viam/proto/common/index.html#viam.proto.common.ResourceName)): The ResourceName of this Resource.

**Example:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.get_resource_name).

### Close

Safely shut down the resource and prevent further use.

- [Python](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-8-0)
- [Go](https://docs.viam.com/reference/apis/components/power-sensor/#tabset-referenceapiscomponentspower-sensor-8-1)

**Parameters:**

- None.

**Returns:**

- None.

**Example:**

```python

```

For more information, see the [Python SDK Docs](https://python.viam.dev/autoapi/viam/components/power_sensor/client/index.html#viam.components.power_sensor.client.PowerSensorClient.close).
