Skip to main content

BatteryState

Represents battery charge level, voltage, current, and charging status.

Attributes:

Attribute

Type

Description

header

Header

Battery metadata header

temperature

float | None

Temperature, unit: degrees Celsius

charge

float | None

Current charge, unit: Ah

capacity

float | None

Capacity, unit: Ah

serial_number

str

Battery serial number

Read-only attributes:

Attribute

Type

Description

percentage

float

Charge percentage, range 0.0 ~ 100.0

voltage

float | None

Voltage, unit: V

current

float | None

Current, unit: A; negative values typically indicate discharging

status_code

int

Raw power supply status code

power_supply_status

str

Human-readable status, e.g. "Charging", "Discharging", "Full", "NotCharging", "Unknown"

timestamp

float

Second-precision timestamp, equivalent to header.timestamp

is_charging

bool

Whether the battery is currently charging

is_low

bool

Whether charge is below 20%

is_critical

bool

Whether charge is below 10%

BatteryState​

Signature:

BatteryState(
percentage: float,
voltage: float | None = None,
current: float | None = None,
status: int = 0,
header: Header | None = None,
temperature: float | None = None,
charge: float | None = None,
capacity: float | None = None,
serial_number: str = "",
)

Description:

Constructs a BatteryState instance.

Parameters:

Parameter

Type

Required

Description

percentage

float

Yes

Charge percentage, typically in range 0.0 ~ 100.0

voltage

float | None

No

Voltage, unit: V

current

float | None

No

Current, unit: A; negative values typically indicate discharging

status

int

No

Raw power supply status code: 0 unknown / 1 charging / 2 discharging / 3 not charging / 4 full

header

Header | None

No

Battery metadata header; uses default Header when omitted or None

temperature

float | None

No

Temperature, unit: degrees Celsius

charge

float | None

No

Current charge, unit: Ah

capacity

float | None

No

Capacity, unit: Ah

serial_number

str

No

Battery serial number

Returns:

BatteryState instance.

Raises:

None.

to_numpy​

Signature:

BatteryState.to_numpy() -> dict[str, np.float32]

Description:

Returns a dictionary of core numeric fields. Includes percentage; optional fields voltage / current / temperature / charge / capacity are included when not None.

Parameters:

No parameters.

Returns:

dict[str, np.float32].

Raises:

None.