1 # When parsing 'upower --dump'
7 # When parsing 'upower --monitor-detail'
8 /^\
[[0-9]+:[0-9]+:[0-9]+\.
[0-9]+\
][ \t]+device changed
:[ \t]+/ {
13 / native
-path
:/ && device
["path"] {
14 device
["native_path"] = $
2
19 / battery
/ && device
["path"] {
20 device
["is_battery"] =
1
24 / state
:/ && device
["is_battery"] {
25 device
["battery_state"] = $
2
29 / energy
:/ && device
["is_battery"] {
34 / energy
-full
:/ && device
["is_battery"] {
35 device
["energy_full"] = $
2
39 / percentage
:/ && device
["is_battery"] {
40 device
["battery_percentage"] = $
2
41 sub("%$", "", device
["battery_percentage"])
45 /^$
/ && device
["is_battery"] {
46 print("battery_state" , aggregate_battery_state
())
47 print("battery_percentage", aggregate_battery_percentage
())
52 / line
-power
/ && device
["path"] {
53 device
["is_line_power"] =
1
57 / online
:/ && device
["is_line_power"] {
58 device
["line_power_online"] = $
2
62 /^$
/ && device
["is_line_power"] {
63 print("line_power", device
["line_power_online"])
72 function aggregate_battery_percentage
( bat
, curr
, full
) {
73 _battery_energy
[device
["native_path"]] = device
["energy"]
74 _battery_energy_full
[device
["native_path"]] = device
["energy_full"]
75 for (bat in _battery_energy
) {
76 curr = curr
+ _battery_energy
[bat
]
77 full = full
+ _battery_energy_full
[bat
]
79 return ((curr
/ full
) * 100)
82 function aggregate_battery_state
( curr
, bat
, new
) {
83 _battery_state
[device
["native_path"]] = device
["battery_state"]
84 curr = device
["battery_state"]
85 for (bat in _battery_state
) {
86 new = _battery_state
[bat
]
87 if (new ==
"discharging") {
89 } else if (curr
!= "discharging" && new ==
"charging") {