Power API
Variable: battery
Type: Battery
The Power API provides information about the device's battery.
import { battery } from "power";
console.log(Math.floor(battery.chargeLevel) + "%");
Variable: charger
Type: Charger
The Power API provides information about the device's charging status.
import { charger } from "power";
console.log("The charger " + (charger.connected ? "is" : "is not") + " connected");
Interface: Battery
A Battery object represents the properties and events of a device's battery.
Properties
chargeLevel
number
Current battery charge level, as a percentage of maximum charge.
Between 0
and 100
inclusive.
charging
boolean
Flag indicating whether the battery is currently charging or not.
onchange
((this: Charger, event: Event) => any) or undefined
Event handler for the change
event.
Interface: Charger
A Charger object represents the properties and events associated with a power charger that may be connected to the device.
Properties
connected
boolean
Indicates whether a charger is connected, or not.
onchange
((this: Charger, event: Event) => any) or undefined
Event handler for the change
event.
powerIsGood
boolean or undefined
Indicates whether the power received from the charger is good or not.
If no charger is connected, or the power quality cannot be determined,
the value is undefined
.