Type Function Return value Table Revision Release 2022.3683 Keywords battery, batteryState, getState See also batteryState.init() batteryState.*
Reads the current battery state. This method returns a table of results immediately, with the following properties:
level
— A number value indicating the battery level, in the range of 0
to 1
, or -1
if no battery.
state
— A string representing the state of the battery. Possible values include "unplugged"
, "charging"
, "full"
, or "unknown"
.
isError
— Boolean value indicating whether an error occurred.
If you want a persistent method of checking the battery state, you should follow the
batteryState.getState()
local batteryState = require( "plugin.batteryState" ) -- Initialize plugin without state listener batteryState.init() -- Get current battery state local batt = batteryState.getState() print( "Level: " .. tostring(batt.level) ) print( "State: " .. tostring(batt.state) ) print( "isError: " .. tostring(batt.isError) )