Categories
DailyOps

How to enumerate power sources and display battery status

Enumerate power sources and display battery status using UPower a System-wide Power Management daemon.

Display help information.

$ upower --help
Usage:
  upower [OPTION?] UPower tool

Help Options:
  -h, --help           Show help options

Application Options:
  -e, --enumerate      Enumerate objects paths for devices
  -d, --dump           Dump all parameters for all objects
  -w, --wakeups        Get the wakeup data
  -m, --monitor        Monitor activity from the power daemon
  --monitor-detail     Monitor with detail
  -i, --show-info      Show information about object path
  -v, --version        Print version of client and daemon

Display client and daemon version.

$ upower --version
UPower client version 0.99.17
UPower daemon version 0.99.17

Display information about every object.

$ upower --dump   
Device: /org/freedesktop/UPower/devices/mouse_hidpp_battery_0
  native-path:          hidpp_battery_0
  model:                M720 Triathlon Multi-Device Mouse
  serial:               405e-20-5f-27-17
  power supply:         no
  updated:              Sun Apr 10 23:31:35 2022 (31 seconds ago)
  has history:          yes
  has statistics:       yes
  mouse
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    battery-level:       full
    percentage:          100% (should be ignored)
    icon-name:          'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_hidpp_battery_1
  native-path:          hidpp_battery_1
  model:                K850 Performance Wireless Keyboard
  serial:               4062-e2-a1-5f-0b
  power supply:         no
  updated:              Sun Apr 10 23:31:35 2022 (31 seconds ago)
  has history:          yes
  has statistics:       yes
  keyboard
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    battery-level:       full
    percentage:          100% (should be ignored)
    icon-name:          'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
  power supply:         no
  updated:              Sun Apr 10 23:05:06 2022 (1620 seconds ago)
  has history:          no
  has statistics:       no
  unknown
    warning-level:       none
    percentage:          0%
    icon-name:          ''

Daemon:
  daemon-version:  0.99.17
  on-battery:      no
  lid-is-closed:   no
  lid-is-present:  no
  critical-action: PowerOff

Enumerate objects.

$ upower --enumerate
/org/freedesktop/UPower/devices/mouse_hidpp_battery_0
/org/freedesktop/UPower/devices/keyboard_hidpp_battery_1
/org/freedesktop/UPower/devices/DisplayDevice

Display information about specific object.

$ upower --show-info /org/freedesktop/UPower/devices/keyboard_hidpp_battery_1
  native-path:          hidpp_battery_1
  model:                K850 Performance Wireless Keyboard
  serial:               4062-e2-a1-5f-0b
  power supply:         no
  updated:              Sun Apr 10 23:31:35 2022 (106 seconds ago)
  has history:          yes
  has statistics:       yes
  keyboard
    present:             yes
    rechargeable:        yes
    state:               fully-charged
    warning-level:       none
    battery-level:       full
    percentage:          100% (should be ignored)
    icon-name:          'battery-full-charged-symbolic'