Clear MPD state on non-0 exit from MPD song sensor
[khatus.git] / bin / khatus_controller
index c56370e..72136d0 100755 (executable)
@@ -2,13 +2,22 @@
 
 /^OK/ { debug("OK line", $0) }
 
+/^ERROR in:MPD.*NON_ZERO_EXIT_CODE/ {
+    for (mpd_key in db) {
+        if (mpd_key ~ "^mpd_") {
+            delete db[mpd_key]
+        }
+    }
+    next
+}
+
 /^ERROR/ {
-       debug("ERROR line", $0)
-       shift()
-       msg_head = $1
-       shift()
-       msg_body = $0
-       alert_trigger_hi(msg_head, "KhatusSensorError", msg_body)
+    debug("ERROR line", $0)
+    shift()
+    msg_head = $1
+    shift()
+    msg_body = $0
+    alert_trigger_hi(msg_head, "KhatusSensorError", msg_body)
 }
 
 /^OK in:ENERGY battery/\
 {
     shift()
     shift()
-    db["net_wifi_status"] = $0
+    set_net_wifi_status()
 }
 
 /^OK in:BLUETOOTH_POWER/\
     db["mpd_status_percent"] = $3
 }
 
-/^OK in:WEATHER/\
+/^OK in:WEATHER temperature/\
 {
+    shift()
     shift()
     shift()
     db["weather_temperature"] = $0
 }
 
+/^OK in:WEATHER phenomenon/\
+{
+    shift()
+    shift()
+    shift()
+    alert_trigger_low("weather_phenomenon", "WeatherPhenomenon", $0)
+}
+
 /^OK in:DATE_TIME/\
 {
     shift()
@@ -213,7 +231,7 @@ function alert_check_mpd(    curr, prev, name, body) {
                 " - " db_mpd_song["Album:"] \
                 " - " db_mpd_song["Title:"]
         }
-        alert_trigger_low("alert_check_mpd", "NowPlaying", body)
+        alert_trigger_low("alert_check_mpd", "MpdNowPlaying", body)
     }
 }
 
@@ -338,6 +356,12 @@ function set_disk_io(    curr_w, curr_r, prev_w, prev_r) {
     db["disk_io_diff_r"] = curr_r - prev_r
 }
 
+function set_net_wifi_status(    interface) {
+    interface = $1
+    shift()
+    db["net_wifi_status", interface] = $0
+}
+
 function set_net_addr_io(    \
     interface, address, io_curr_w, io_curr_r, io_prev_w, io_prev_r\
 ) {
@@ -475,7 +499,7 @@ function make_status_net(    \
                     io_stat = "--"
                 }
                 if (interface ~ "^w") {
-                    label = label ":" db["net_wifi_status"]
+                    label = label ":" db["net_wifi_status", interface]
                 }
                 if (++count_printed > 1) {
                     sep = "  "
This page took 0.039744 seconds and 4 git commands to generate.