Module upower_dbus
Get information about your power devices using UPower and DBus.
Requiring this module will return the UPower Manager singleton.
Example:
GLib = require("lgi").GLib ctx = GLib.MainLoop():get_context() upower = require("upower_dbus") -- What version of UPower is in use? upower.Manager.DaemonVersion -- Are we using a battery? upower.Manager.OnBattery -- true or false -- Enumerate the Device Types known by UPower for _, v in ipairs(upower.enums.DeviceType) do print(v) end -- Say that the first device is a battery battery = upower.Manager.devices[1] print(battery.Percentage) -- may print 100.0 -- Update the devices in case something changed ctx:iteration() -- The battery discharged a bit battery.Percentage -- may print 99.0 battery.WarningLevel -- CamelCase, may print 4.0 battery.warninglevel -- lower case, may print Critical
Info:
- Copyright: 2017 - 2025 Stefano Mazzucco
- License: Apache License, version 2.0
- Author: Stefano Mazzucco
Fields
| upower.display_device | The display device. |
Enumerations
| upower.enums | UPower Enumerations. |
| DeviceType | The type of power source |
| BatteryState | The state of the battery. |
| BatteryTechnology | The technology used by the battery. |
| BatteryWarningLevel | The warning level of the battery. |
| BatteryLevel | The level of the battery for devices which do not report a percentage but rather a coarse battery level. |
Device
| upower.create_device (path) | Create a new UPower Device. |
Manager
| upower.Manager | The UPower Manager that proxies the UPower DBus interface. |
| upower.Manager.devices | Array of UPower Device objects. |
| upower.Manager:refresh_devices () | Refresh the list of devices upower.Manager.devices. |
Fields
- upower.display_device
-
The display device.
The "display device" is a composite device that represents the status icon to show in desktop environments. Its path is guaranteed to be /org/freedesktop/UPower/devices/DisplayDevice.
Enumerations
- upower.enums
- UPower Enumerations. The upower.enums table contains the below Lua Enumerations.
- DeviceType
-
The type of power source
Fields:
- Unknown
- Line Power
- Battery
- Ups
- Monitor
- Mouse
- Keyboard
- Pda
- Phone
- Media Player
- Tablet
- Computer
- Gaming Input
- Pen
- Touchpad
- Modem
- Network
- Headset
- Speakers
- Headphones
- Video
- Other Audio
- Remote Control
- Printer
- Scanner
- Camera
- Wearable
- Toy
- Bluetooth Generic
- BatteryState
-
The state of the battery.
This property is only valid if the device is a battery.
Fields:
- Unknown
- Charging
- Discharging
- Empty
- Fully charged
- Pending charge
- Pending discharge
- BatteryTechnology
-
The technology used by the battery.
This property is only valid if the device is a battery.
Fields:
- Unknown
- Lithium ion
- Lithium polymer
- Lithium iron phosphate
- Lead acid
- Nickel cadmium
- Nickel metal hydride
- BatteryWarningLevel
-
The warning level of the battery.
This property is only valid if the device is a battery.
Fields:
- Unknown
- None
- Discharging (only for UPSes)
- Low
- Critical
- Action
- BatteryLevel
-
The level of the battery for devices which do not report a percentage but
rather a coarse battery level. If the value is None, then the device does
not support coarse battery reporting, and the percentage should be used
instead.
Fields:
- Unknown
- None the battery does not use a coarse level of battery reporting
- Low
- Critical
- Normal
- High
- Full
Device
- upower.create_device (path)
-
Create a new UPower Device.
You can use the EnumerateDevices method on the Manager object to obtain the correct device paths. But the objects are also available from the
Manager.devicesproperty.The
Type,State,TechnologyandWarningLeveluppercase numeric properties have a lowercase string equivalent.For example:
device.Type -- numeric e.g. 2.0 device.type -- string e.g. "Battery"Parameters:
- path The DBus object path for the device.
See also:
Manager
- upower.Manager
-
The UPower Manager that proxies the UPower DBus
interface.
Additionally the devices field contains the available Device objects.
See also:
- upower.Manager.devices
-
Array of UPower Device objects.
See also:
- upower.Manager:refresh_devices ()
-
Refresh the list of devices upower.Manager.devices.
Normally you should not need to call this method as it's called the first time the module is
required and whenever a device is added or removed.