batteryState.init()

Type Function
Return value none
Revision Release 2022.3683
Keywords battery, batteryState, init
See also batteryState.*

Overview

Initializes the plugin and optionally defines a listener function for battery events.

Syntax

batteryState.init( [listener] )
listener (optional)

Listener. The listener function invoked when the battery state/level changes. This function will receive batteryStateEvent events.

Note

If you simply want battery state results as a one-time call, you can use the batteryState.getState() method instead of providing a listener function reference and waiting for a state/level change response.

Example

local batteryState = require( "plugin.batteryState" )
local json = require( "json" )

local function batteryListener( event )
    print( "Battery State event:" )
    print( json.prettify(event) )
end

-- Initialize plugin with state listener
batteryState.init( batteryListener )