Add energy state change alert
authorSiraaj Khandkar <siraaj@khandkar.net>
Wed, 1 Aug 2018 03:08:13 +0000 (23:08 -0400)
committerSiraaj Khandkar <siraaj@khandkar.net>
Wed, 1 Aug 2018 03:08:13 +0000 (23:08 -0400)
bin/khatus_controller

index 411589d..2e483b0 100755 (executable)
@@ -5,7 +5,8 @@
 {
     split_msg_parts()
     sub("%$", "", $2)
-    db["energy_state"]      = $1
+    db["energy_state_prev"] = db["energy_state_curr"]
+    db["energy_state_curr"] = $1
     db["energy_percentage"] = ensure_numeric($2)
     alert_check_energy()
 }
 #       - priority
 #       - snooze time (if already alerted, when to re-alert?)
 #       - text: subject/body
-function alert_check_energy(    from, dbg, state, remaining, subj, body) {
+function alert_check_energy(    \
+    from, dbg, state_curr, state_prev, remaining, subj, body\
+) {
     from = "alert_check_energy"
 
-    state     = db["energy_state"]
-    remaining = db["energy_percentage"]
+    state_curr = db["energy_state_curr"]
+    state_prev = db["energy_state_prev"]
+    remaining  = db["energy_percentage"]
 
-    dbg["state"] = state
+    dbg["state_curr"] = state_curr
     dbg["remaining"] = remaining
     debug(from, dbg)
 
-    if (state == "discharging") {
+    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)
@@ -283,7 +291,7 @@ function make_status_bar(    position, bar, sep, i, j) {
 }
 
 function make_status_energy(    state, direction_of_change) {
-    state = db["energy_state"]
+    state = db["energy_state_curr"]
     if (state == "discharging") {
         direction_of_change = "<"
     } else if (state == "charging") {
This page took 0.020899 seconds and 4 git commands to generate.