diff --git a/Cargo.toml b/Cargo.toml index 3d249ee..88c4aaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,7 @@ tokio = { version = "1", features = ["full"] } toml = "0.5.10" dotenv = "0.15.0" anyhow = "1.0.68" -reqwest = "0.11.13" +reqwest = { version = "0.11.13", features = ["json"] } axum = "0.6.1" serde_repr = "0.1.10" tracing = "0.1.37" diff --git a/src/hue_bridge.rs b/src/hue_bridge.rs index 29452f9..a38d29a 100644 --- a/src/hue_bridge.rs +++ b/src/hue_bridge.rs @@ -38,10 +38,9 @@ impl HueBridge { }; let url = format!("http://{}/api/{}/sensors/{flag}/state", self.addr, self.login); - let json = serde_json::to_string(&FlagMessage{ flag: value }).unwrap(); - let client = reqwest::Client::new(); - let res = client.put(url) - .body(json) + let res = reqwest::Client::new() + .put(url) + .json(&FlagMessage { flag: value }) .send() .block_on(); diff --git a/src/ntfy.rs b/src/ntfy.rs index bc0118b..88fca77 100644 --- a/src/ntfy.rs +++ b/src/ntfy.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use tracing::{warn, error}; -use reqwest::StatusCode; use serde::Serialize; use serde_repr::*; use pollster::FutureExt as _; @@ -118,12 +117,12 @@ impl OnPresence for Ntfy { .set_priority(Priority::Low); // Create the request - let req = reqwest::Client::new() + let res = reqwest::Client::new() .post(self.base_url.clone()) - .body(serde_json::to_string(¬ification).unwrap()); + .json(¬ification) + .send() + .block_on(); - // Send the notification - let res = req.send().block_on(); if let Err(err) = res { error!("Something went wrong while sending the notifcation: {err}"); } else if let Ok(res) = res {