# `BB.Message.Sensor.BatteryState`
[🔗](https://github.com/beam-bots/bb/blob/main/lib/bb/message/sensor/battery_state.ex#L5)

Battery state information.

## Fields

- `voltage` - Voltage in Volts
- `current` - Current in Amperes (negative when discharging)
- `charge` - Charge in Ampere-hours (0 if not measured)
- `capacity` - Capacity in Ampere-hours (full charge, 0 if not measured)
- `percentage` - Charge percentage (0.0 to 1.0, or nil if not measured)
- `power_supply_status` - Status of the power supply
- `power_supply_health` - Health of the power supply
- `present` - Whether battery is present

## Power Supply Status

- `:unknown` - Cannot determine status
- `:charging` - Battery is charging
- `:discharging` - Battery is discharging
- `:not_charging` - Not charging (full or error)
- `:full` - Battery is full

## Power Supply Health

- `:unknown` - Cannot determine health
- `:good` - Battery is healthy
- `:overheat` - Battery is overheating
- `:dead` - Battery is dead
- `:overvoltage` - Voltage too high
- `:cold` - Battery is too cold

## Examples

    alias BB.Message.Sensor.BatteryState

    {:ok, msg} = BatteryState.new(:battery,
      voltage: 12.6,
      current: -0.5,
      percentage: 0.85,
      power_supply_status: :discharging,
      power_supply_health: :good,
      present: true
    )

# `power_supply_health`

```elixir
@type power_supply_health() ::
  :unknown | :good | :overheat | :dead | :overvoltage | :cold
```

# `power_supply_status`

```elixir
@type power_supply_status() ::
  :unknown | :charging | :discharging | :not_charging | :full
```

# `t`

```elixir
@type t() :: %BB.Message.Sensor.BatteryState{
  capacity: float(),
  charge: float(),
  current: float(),
  percentage: float() | nil,
  power_supply_health: power_supply_health(),
  power_supply_status: power_supply_status(),
  present: boolean(),
  voltage: float()
}
```

# `new`

```elixir
@spec new(
  atom(),
  keyword()
) :: {:ok, BB.Message.t()} | {:error, term()}
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
