React-to, rather than poll-for, energy events
[khatus.git] / bin / khatus_parse_upower
diff --git a/bin/khatus_parse_upower b/bin/khatus_parse_upower
new file mode 100755 (executable)
index 0000000..6761508
--- /dev/null
@@ -0,0 +1,55 @@
+#! /usr/bin/awk -f
+
+# When parsing 'upower --dump'
+/^Device:[ \t]+/ {
+    device["path"] = $2
+    next
+}
+
+# When parsing 'upower --monitor-detail'
+/^\[[0-9]+:[0-9]+:[0-9]+\.[0-9]+\][ \t]+device changed:[ \t]+/ {
+    device["path"] = $4
+    next
+}
+
+# BEGIN battery
+/  battery/ && device["path"] {
+    device["is_battery"] = 1
+    next
+}
+
+/    state:/ && device["is_battery"] {
+    device["battery_state"] = $2
+    next
+}
+
+/    percentage:/ && device["is_battery"] {
+    device["battery_percentage"] = $2
+    next
+}
+
+/^$/ && device["is_battery"] {
+    printf("battery %s %s\n", device["battery_state"], device["battery_percentage"])
+}
+# END battery
+
+# BEGIN line-power
+/  line-power/ && device["path"] {
+    device["is_line_power"] = 1
+    next
+}
+
+/    online:/ && device["is_line_power"] {
+    device["line_power_online"] = $2
+    next
+}
+
+/^$/ && device["is_line_power"] {
+    printf("line_power %s\n", device["line_power_online"])
+}
+# END line-power
+
+/^$/ {
+    delete device
+    next
+}
This page took 0.024114 seconds and 4 git commands to generate.