diff --git a/Cargo.lock b/Cargo.lock index 9b0d71b..eee72e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -33,7 +33,6 @@ dependencies = [ "impl_cast", "log", "paste", - "pollster", "rumqttc", "serde", "serde_json", diff --git a/Cargo.toml b/Cargo.toml index 43a58d1..ef138ce 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,6 @@ tokio = { version = "1", features = ["full"] } warp = "0.3" log = "0.4" env_logger = "0.10" -pollster = "0.2.5" toml = "0.5.10" dotenv = "0.15.0" diff --git a/src/devices/ikea_outlet.rs b/src/devices/ikea_outlet.rs index c5ec419..a70863a 100644 --- a/src/devices/ikea_outlet.rs +++ b/src/devices/ikea_outlet.rs @@ -1,5 +1,3 @@ -use pollster::FutureExt as _; - use google_home::errors::ErrorCode; use google_home::{GoogleHomeDevice, device, types::Type, traits}; use rumqttc::{AsyncClient, Publish}; @@ -19,7 +17,13 @@ pub struct IkeaOutlet { impl IkeaOutlet { pub fn new(name: String, zigbee: Zigbee, client: AsyncClient) -> Self { - client.subscribe(zigbee.get_topic(), rumqttc::QoS::AtLeastOnce).block_on().unwrap(); + let c = client.clone(); + let topic = zigbee.get_topic().to_owned(); + // @TODO Handle potential errors here + tokio::spawn(async move { + c.subscribe(topic, rumqttc::QoS::AtLeastOnce).await.unwrap(); + }); + Self{ name, zigbee, client, last_known_state: false } } } @@ -97,7 +101,10 @@ impl traits::OnOff for IkeaOutlet { // @TODO Handle potential errors here // @NOTE We are blocking here, ideally this function would just be async, however that is // currently not really possible - self.client.publish(topic + "/set", rumqttc::QoS::AtLeastOnce, false, serde_json::to_string(&message).unwrap()).block_on().unwrap(); + let client = self.client.clone(); + tokio::spawn(async move { + client.publish(topic + "/set", rumqttc::QoS::AtLeastOnce, false, serde_json::to_string(&message).unwrap()).await.unwrap(); + }); Ok(()) }