Pass expected urgency format

This commit is contained in:
niten 2023-05-18 14:06:00 -07:00
parent db1f07d9f0
commit 56d52a5beb
1 changed files with 9 additions and 1 deletions

View File

@ -19,6 +19,11 @@
[:body (sized-string 1 256)] [:body (sized-string 1 256)]
[:urgency [:and :int [:>= 0] [:<= 10]]]])) [:urgency [:and :int [:>= 0] [:<= 10]]]]))
(defn- codify-urgency [urgency]
(cond (<= 0 urgency 3) :low
(<= 4 urgency 7) :normal
(<= 8 urgency 10) :critical))
(defn listen! [& {app :app mqtt-client (defn listen! [& {app :app mqtt-client
:mqtt-client topic :mqtt-client topic
:topic logger :topic logger
@ -30,7 +35,10 @@
(let [note (:payload note-msg)] (let [note (:payload note-msg)]
(if (t/validate Notification note) (if (t/validate Notification note)
(when (>= (:urgency note) urgency-threshold) (when (>= (:urgency note) urgency-threshold)
(notify/send-notification! mqtt-client (assoc note :app app)) (notify/send-notification! mqtt-client
(-> note
(assoc :app app)
(update :urgency codify-urgency)))
(log/info! logger (format "ignoring low-urgency message (%s): %s" (log/info! logger (format "ignoring low-urgency message (%s): %s"
(:urgency note) (:urgency note)
(:summary note)))) (:summary note))))