React-to, rather than poll-for, energy events
[khatus.git] / bin / khatus_parse_upower
CommitLineData
ab99b556
SK
1#! /usr/bin/awk -f
2
3# When parsing 'upower --dump'
4/^Device:[ \t]+/ {
5 device["path"] = $2
6 next
7}
8
9# When parsing 'upower --monitor-detail'
10/^\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\][ \t]+device changed:[ \t]+/ {
11 device["path"] = $4
12 next
13}
14
15# BEGIN battery
16/ battery/ && device["path"] {
17 device["is_battery"] = 1
18 next
19}
20
21/ state:/ && device["is_battery"] {
22 device["battery_state"] = $2
23 next
24}
25
26/ percentage:/ && device["is_battery"] {
27 device["battery_percentage"] = $2
28 next
29}
30
31/^$/ && device["is_battery"] {
32 printf("battery %s %s\n", device["battery_state"], device["battery_percentage"])
33}
34# END battery
35
36# BEGIN line-power
37/ line-power/ && device["path"] {
38 device["is_line_power"] = 1
39 next
40}
41
42/ online:/ && device["is_line_power"] {
43 device["line_power_online"] = $2
44 next
45}
46
47/^$/ && device["is_line_power"] {
48 printf("line_power %s\n", device["line_power_online"])
49}
50# END line-power
51
52/^$/ {
53 delete device
54 next
55}
This page took 0.038113 seconds and 4 git commands to generate.