Module: lib-tde.function.battery

This module contains useful helper functions when working with batteries.

To get the charging status of the battery you must do an asynchronous call to not block the main thread a function call must be wrapped in a awful.spawn.easy_async_with_shell

awful.spawn.easy_async_with_shell(lib-tde.function.battery.chargedScript, function(stdout)
   lib-tde.function.battery.isBatteryCharging(stdout) -- returns is the battery is charging e.g. false
end)

Another example is to check the current battery percentage

awful.spawn.easy_async_with_shell(lib-tde.function.battery.upowerBatteryScript, function(stdout)
   lib-tde.function.battery.getBatteryInformationFromUpower(stdout) -- returns battery percentage e.g. 87
end)

Info:

  • Copyright: 2020 Tom Meyers
  • Author: Tom Meyers

Static module functions

lib-tde.function.battery.getBatteryPath () -> () Check if a battery exists
lib-tde.function.battery.isBatteryCharging () -> () Return true if the battery is charging
lib-tde.function.battery.getBatteryPercentage () -> () Return the percentage of the battery or nil (if no battery exists)


Static module functions

lib-tde.function.battery.getBatteryPath () -> ()
Check if a battery exists

Returns:

    string The percentage of the battery

Usage:

    -- This will /sys/class/power_supply/BAT0 if it exists
     lib-tde.function.battery.getBatteryPath() -- return location of the battery state
lib-tde.function.battery.isBatteryCharging () -> ()
Return true if the battery is charging

Returns:

    boolean True if it is charging

Usage:

    -- This will return True if charging
      lib-tde.function.battery.isBatteryCharging() -- True
lib-tde.function.battery.getBatteryPercentage () -> ()
Return the percentage of the battery or nil (if no battery exists)

Returns:

    number The percentage of the battery

Usage:

    -- This will 100 if fully charged
     lib-tde.function.battery.getBatteryPercentage() -- return percentage of battery
generated by LDoc 1.4.6 Build with 💜 By F0xedb Last updated 2021-05-21 03:30:15