+ fields_shift()
+ db["datetime"] = $0
+ output_msg_status_bar(make_status_bar())
+}
+
+# TODO: Generalize alert spec lang
+# - trigger threshold
+# - above/bellow/equal to threshold value
+# - priority
+# - snooze time (if already alerted, when to re-alert?)
+# - text: subject/body
+function alert_check_energy( \
+ from, dbg, state_curr, state_prev, remaining, subj, body\
+) {
+ from = "alert_check_energy"
+
+ state_curr = db["energy_state_curr"]
+ state_prev = db["energy_state_prev"]
+ remaining = db["energy_percentage"]
+
+ dbg["state_curr"] = state_curr
+ dbg["remaining"] = remaining
+ debug(from, dbg)
+
+ if (state_curr == "discharging") {
+ if (state_prev == "charging") {
+ alert_trigger_low(from, "Unplugged", "")
+ }
+
+ if (remaining < 5) {
+ subj = "Energy_CRITICALLY_Low"
+ body = sprintf("%d%% CHARGE NOW!!! GO GO GO!!!", remaining)
+ alert_trigger_hi(from, subj, body)
+ } else if (remaining < 10) {
+ subj = "Energy_Very_Low"
+ body = sprintf("%d%% Plug it in ASAP.", remaining)
+ alert_trigger_hi(from, subj, body)
+ } else if (remaining < 15) {
+ subj = "Energy_Low"
+ body = sprintf("%d%% Get the charger.", remaining)
+ alert_trigger_hi(from, subj, body)
+ } else if (remaining < 20) {
+ subj = "Energy_Low"
+ body = sprintf("%d%% Get the charger.", remaining)
+ alert_trigger_med(from, subj, body)
+ } else if (remaining < 50) {
+ if (!state__alerts__energy__notified_bellow_half) {
+ state__alerts__energy__notified_bellow_half = 1
+ subj = "Energy_Bellow_Half"
+ body = sprintf("%d%% Where is the charger?", remaining)
+ alert_trigger_med(from, subj, body)
+ }
+ }
+ } else {
+ # TODO: Reconsider the competing global-state organizing-conventions
+ state__alerts__energy__notified_bellow_half = 0
+ }