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" && \
15 line_power_prev = line_power_curr
17 if (line_power_curr ==
"no" && line_power_prev
!= "no") {
18 msg_out_alert_low
("PowerUnplugged", "")
23 $
2 ==
"khatus_sensor_energy" && \
25 $
4 ==
"battery_state" {
26 battery_state_prev = battery_state_curr
27 battery_state_curr = $
5
31 $
2 ==
"khatus_sensor_energy" && \
33 $
4 ==
"battery_percentage" {
34 # TODO: Re-think the spec - can't rely on order of keys
35 battery_percentage = num_ensure_numeric
($
5)
36 if (battery_state_curr ==
"discharging") {
37 for (threshold in bat_alert_spec
) {
38 threshold = num_ensure_numeric
(threshold
)
39 if (battery_percentage
<= threshold
&& !_alerted
[threshold
]) {
40 split(bat_alert_spec
[threshold
], alert
, "|")
43 body =
sprintf("%d%% %s", battery_percentage
, alert
[3])
44 msg_out_alert
(priority
, subject
, body
)