Split batter and line_power alerts
[khatus.git] / bin / khatus_sensor_bluetooth_power
CommitLineData
f37162a4
SK
1#! /bin/sh
2
3set -e
4
5echo -e 'show \n quit' \
6| bluetoothctl \
7| awk '
8 /^Controller / {
9 controller = $2;
10 controllers[++ctrl_count] = controller;
11 }
12 /^\t[A-Z][A-Za-z]+:/ {
13 key = $1;
14 sub(":$", "", key);
15 val = $2;
16 for (i=3; i<=NF; i++) {
17 val = val " " $i};
18 data[controller, key] = val;
19 }
20 END {
21 # Using the 1st seen controller. Should we select specific instead?
22 power_status = data[controllers[1], "Powered"];
23 if (ctrl_count > 0) {
24 if (power_status == "no") {
25 power_status = "off"
26 } else if (power_status == "yes") {
27 power_status = "on"
28 } else {
29 printf("Unexpected bluetooth power status: %s\n", power_status)\
30 > "/dev/stderr";
31 power_status = "ERROR"
32 }
33 } else {
34 power_status = "off" # TODO: Perhaps use differentiated marker?
35 }
36 printf("%s\n", power_status);
37 }'
This page took 0.021898 seconds and 4 git commands to generate.