Merge branch 'master' of ssh://git.fudo.org:2222/fudo-public/WallFly
This commit is contained in:
commit
f7bde8592f
30
flake.lock
30
flake.lock
|
@ -9,11 +9,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1655801580,
|
"lastModified": 1663870497,
|
||||||
"narHash": "sha256-4XUFDP1ES1KNWwDukQEixCe4uV7Z951kgaVAFhXI2ew=",
|
"narHash": "sha256-gnoyYWvZl64WBqR3tf9bKHAznEtBCHmwx7taHghH9Lw=",
|
||||||
"owner": "jlesquembre",
|
"owner": "jlesquembre",
|
||||||
"repo": "clj-nix",
|
"repo": "clj-nix",
|
||||||
"rev": "579141e009200fcd28d251731e9ac5ba46a1ec2a",
|
"rev": "23d9daacc80e634df078c4c6e34d592e1593d84c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -31,11 +31,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1644227066,
|
"lastModified": 1658746384,
|
||||||
"narHash": "sha256-FHcFZtpZEWnUh62xlyY3jfXAXHzJNEDLDzLsJxn+ve0=",
|
"narHash": "sha256-CCJcoMOcXyZFrV1ag4XMTpAPjLWb4Anbv+ktXFI1ry0=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "devshell",
|
"repo": "devshell",
|
||||||
"rev": "7033f64dd9ef8d9d8644c5030c73913351d2b660",
|
"rev": "0ffc7937bb5e8141af03d462b468bd071eb18e1b",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -61,11 +61,11 @@
|
||||||
},
|
},
|
||||||
"flake-utils_2": {
|
"flake-utils_2": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1644229661,
|
"lastModified": 1656928814,
|
||||||
"narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=",
|
"narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797",
|
"rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -76,11 +76,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1656265786,
|
"lastModified": 1672580127,
|
||||||
"narHash": "sha256-A9RkoGrxzsmMm0vily18p92Rasb+MbdDMaSnzmywXKw=",
|
"narHash": "sha256-3lW3xZslREhJogoOkjeZtlBtvFMyxHku7I/9IVehhT8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "cd90e773eae83ba7733d2377b6cdf84d45558780",
|
"rev": "0874168639713f547c05947c76124f78441ea46c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -98,11 +98,11 @@
|
||||||
},
|
},
|
||||||
"utils": {
|
"utils": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1656065134,
|
"lastModified": 1667395993,
|
||||||
"narHash": "sha256-oc6E6ByIw3oJaIyc67maaFcnjYOz1mMcOtHxbEf9NwQ=",
|
"narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "bee6a7250dd1b01844a2de7e02e4df7d8a0a206c",
|
"rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -14,14 +14,21 @@
|
||||||
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence)
|
org.eclipse.paho.client.mqttv3.persist.MemoryPersistence)
|
||||||
(:gen-class))
|
(:gen-class))
|
||||||
|
|
||||||
|
(defn- exit! [status msg]
|
||||||
|
(println msg)
|
||||||
|
(System/exit status))
|
||||||
|
|
||||||
(defn- create-mqtt-client [broker-uri client-id mqtt-username passwd]
|
(defn- create-mqtt-client [broker-uri client-id mqtt-username passwd]
|
||||||
(let [opts (doto (MqttConnectOptions.)
|
(let [opts (doto (MqttConnectOptions.)
|
||||||
(.setCleanSession true)
|
(.setCleanSession true)
|
||||||
(.setAutomaticReconnect true)
|
(.setAutomaticReconnect true)
|
||||||
(.setPassword (char-array passwd))
|
(.setPassword (char-array passwd))
|
||||||
(.setUserName mqtt-username))]
|
(.setUserName mqtt-username))]
|
||||||
(doto (MqttClient. broker-uri client-id (MemoryPersistence.))
|
(try
|
||||||
(.connect opts))))
|
(doto (MqttClient. broker-uri client-id (MemoryPersistence.))
|
||||||
|
(.connect opts))
|
||||||
|
(catch Exception e
|
||||||
|
(exit! 1 (.getMessage e))))))
|
||||||
|
|
||||||
(defn- shell-exec [& args]
|
(defn- shell-exec [& args]
|
||||||
(let [{:keys [exit out err]} (apply shell/sh args)]
|
(let [{:keys [exit out err]} (apply shell/sh args)]
|
||||||
|
@ -45,7 +52,10 @@
|
||||||
(.setRetained retained)))
|
(.setRetained retained)))
|
||||||
|
|
||||||
(defn- send-message [client topic msg & {:keys [retained] :or {retained false}}]
|
(defn- send-message [client topic msg & {:keys [retained] :or {retained false}}]
|
||||||
(.publish client topic (create-message msg retained)))
|
(try
|
||||||
|
(.publish client topic (create-message msg retained))
|
||||||
|
(catch Exception e
|
||||||
|
(exit! 1 (.getMessage e)))))
|
||||||
|
|
||||||
(defn- create-reporter [client time-to-idle location user host host-device]
|
(defn- create-reporter [client time-to-idle location user host host-device]
|
||||||
(let [base-topic (format "homeassistant/binary_sensor/wallfly_%s_%s"
|
(let [base-topic (format "homeassistant/binary_sensor/wallfly_%s_%s"
|
||||||
|
@ -93,10 +103,6 @@
|
||||||
["-t" "--time-to-idle SECONDS" "Number of seconds before considering this host idle."]
|
["-t" "--time-to-idle SECONDS" "Number of seconds before considering this host idle."]
|
||||||
["-d" "--delay-time SECONDS" "Time to wait before polling for idle time."]])
|
["-d" "--delay-time SECONDS" "Time to wait before polling for idle time."]])
|
||||||
|
|
||||||
(defn- exit! [status msg]
|
|
||||||
(println msg)
|
|
||||||
(System/exit status))
|
|
||||||
|
|
||||||
(defn- get-key [opts k]
|
(defn- get-key [opts k]
|
||||||
(if-let [opt (get opts k)]
|
(if-let [opt (get opts k)]
|
||||||
[k opt]
|
[k opt]
|
||||||
|
|
Loading…
Reference in New Issue