2 # TODO: Read spec from a file
3 bat_alert_spec
[100] =
"low|Energy_Bellow_Full|Must have perfection!"
4 bat_alert_spec
[50] =
"low|Energy_Bellow_Half|Where is the charger?"
5 bat_alert_spec
[20] =
"med|Energy_Low|Get the charger."
6 bat_alert_spec
[15] =
"med|Energy_Low|Get the charger!"
7 bat_alert_spec
[10] =
"hi|Energy_Low|Plug it in, ASAP!"
8 bat_alert_spec
[5] =
"hi|Energy_CRITICALLY_Low|CHARGE NOW!!! GO GO GO!!!"
12 $
2 ==
"khatus_sensor_energy" && \
14 line_power_prev = line_power_curr
16 if (line_power_curr ==
"no" && line_power_prev
!= "no") {
17 alert
("low", "PowerUnplugged", "")
22 $
2 ==
"khatus_sensor_energy" && \
23 $
3 ==
"battery_state" {
24 battery_state_prev = battery_state_curr
25 battery_state_curr = $
4
29 $
2 ==
"khatus_sensor_energy" && \
30 $
3 ==
"battery_percentage" {
31 # TODO: Re-think the spec - can't rely on order of keys
32 battery_percentage = util_ensure_numeric
($
4)
33 if (battery_state_curr ==
"discharging") {
34 for (threshold in bat_alert_spec
) {
35 threshold = util_ensure_numeric
(threshold
)
36 if (battery_percentage
<= threshold
&& !_alerted
[threshold
]) {
37 split(bat_alert_spec
[threshold
], msg
, "|")
40 body =
sprintf("%d%% %s", battery_percentage
, msg
[3])
41 alert
(priority
, subject
, body
)