battery
battery returns the first battery's information as a native BatteryInfo?.
Signature
battery(): BatteryInfo?tyrus
import { BatteryInfo, battery } from "tyrus:os";
const info: BatteryInfo? = battery();
if (info) {
print(`${info.level * 100.0}%, charging: ${info.charging}`);
}BatteryInfo Fields
| Field | Type | Meaning |
|---|---|---|
level | f32 | State of charge, from 0.0 to 1.0. |
charging | boolean | Whether the battery is currently charging. |
timeToFull | u32? | Seconds until full, absent unless currently charging. |
timeToEmpty | u32? | Seconds until empty, absent unless currently discharging. |
Absence is a valid outcome
Desktops and most servers have no battery at all, that is a normal result, not a failure.
