3 # When parsing 'upower --dump'
9 # When parsing 'upower --monitor-detail'
10 /^\
[[0-9]+:[0-9]+:[0-9]+\.
[0-9]+\
][ \t]+device changed
:[ \t]+/ {
15 / native
-path
:/ && device
["path"] {
16 device
["native_path"] = $
2
21 / battery
/ && device
["path"] {
22 device
["is_battery"] =
1
26 / state
:/ && device
["is_battery"] {
27 device
["battery_state"] = $
2
31 / energy
:/ && device
["is_battery"] {
36 / energy
-full
:/ && device
["is_battery"] {
37 device
["energy_full"] = $
2
41 / percentage
:/ && device
["is_battery"] {
42 device
["battery_percentage"] = $
2
43 sub("%$", "", device
["battery_percentage"])
47 /^$
/ && device
["is_battery"] {
48 print("battery_state" , aggregate_battery_state
())
49 print("battery_percentage", aggregate_battery_percentage
())
54 / line
-power
/ && device
["path"] {
55 device
["is_line_power"] =
1
59 / online
:/ && device
["is_line_power"] {
60 device
["line_power_online"] = $
2
64 /^$
/ && device
["is_line_power"] {
65 print("line_power", device
["line_power_online"])
74 function aggregate_battery_percentage
( bat
, curr
, full
) {
75 _battery_energy
[device
["native_path"]] = device
["energy"]
76 _battery_energy_full
[device
["native_path"]] = device
["energy_full"]
77 for (bat in _battery_energy
) {
78 curr = curr
+ _battery_energy
[bat
]
79 full = full
+ _battery_energy_full
[bat
]
81 return ((curr
/ full
) * 100)
84 function aggregate_battery_state
( curr
, bat
, new
) {
85 _battery_state
[device
["native_path"]] = device
["battery_state"]
86 curr = device
["battery_state"]
87 for (bat in _battery_state
) {
88 new = _battery_state
[bat
]
89 if (new ==
"discharging") {
91 } else if (curr
!= "discharging" && new ==
"charging") {