diff --git a/src/client.rs b/src/client.rs index 5fcec57..bae119f 100644 --- a/src/client.rs +++ b/src/client.rs @@ -69,12 +69,12 @@ impl Client { let msg_opt = self.stream.next().await; if let Some(Some(msg)) = msg_opt { - self.tx.send(parse_message(msg)?)?; + self.tx.send(parse_message(&msg)?)?; } else { // A "None" means we were disconnected. Try to reconnect... self.tx.send(Message::Disconnected)?; - while let Err(_) = self.client.reconnect().await { + while (self.client.reconnect().await).is_err() { tokio::time::sleep(Duration::from_secs(1)).await; self.tx.send(Message::Reconnecting)?; } @@ -109,11 +109,9 @@ impl Client { Ok(()) } - fn subscibe_to_device_report(&mut self) -> Result<()> { + fn subscibe_to_device_report(&mut self) { self.client .subscribe(&self.topic_device_report, paho_mqtt::QOS_0); - - Ok(()) } /// Runs the Bambu MQTT client. @@ -126,10 +124,10 @@ impl Client { pub async fn run(&mut self) -> Result<()> { self.connect().await?; - self.subscibe_to_device_report()?; + self.subscibe_to_device_report(); loop { - Client::poll(self).await?; + Self::poll(self).await?; } } diff --git a/src/parser.rs b/src/parser.rs index 7a57230..f3678d8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2,7 +2,7 @@ use anyhow::Result; use crate::message::Message; -pub(crate) fn parse_message(message: paho_mqtt::Message) -> Result { +pub(crate) fn parse_message(message: &paho_mqtt::Message) -> Result { let payload_str = String::from_utf8(message.payload().to_vec())?; Ok(Message::Info(payload_str)) } @@ -19,7 +19,7 @@ mod tests { paho_mqtt::QOS_2, ); - let result = parse_message(message).unwrap(); + let result = parse_message(&message).unwrap(); assert_eq!(result, Message::Info(r#"{ "hello": "world" }"#.into())); }