From 9d6488183f05909f8fbf4f7ceabc9d1462b7c8f8 Mon Sep 17 00:00:00 2001 From: Dreaded_X Date: Tue, 10 Jan 2023 00:41:41 +0100 Subject: [PATCH] Small change to how on presence changes the state for IkeaOutlet --- src/devices/ikea_outlet.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/devices/ikea_outlet.rs b/src/devices/ikea_outlet.rs index 7d4b3c6..b2b07c8 100644 --- a/src/devices/ikea_outlet.rs +++ b/src/devices/ikea_outlet.rs @@ -2,7 +2,7 @@ use std::time::Duration; use async_trait::async_trait; use google_home::errors::ErrorCode; -use google_home::{GoogleHomeDevice, device, types::Type, traits}; +use google_home::{GoogleHomeDevice, device, types::Type, traits::{self, OnOff}}; use rumqttc::{AsyncClient, Publish, matches}; use tracing::{debug, trace, error}; use tokio::task::JoinHandle; @@ -101,9 +101,10 @@ impl OnMqtt for IkeaOutlet { tokio::spawn(async move { debug!(id, "Starting timeout ({timeout:?}) for kettle..."); tokio::time::sleep(timeout).await; - // @TODO We need to call set_on(false) in order to turn the device off - // again, how are we going to do this? debug!(id, "Turning kettle off!"); + // @TODO Idealy we would call self.set_on(false), however since we want to do + // it after a timeout we have to put it in a seperate task. + // I don't think we can really get around calling outside function set_on(client, topic, false).await; }) ); @@ -117,7 +118,7 @@ impl OnPresence for IkeaOutlet { // Turn off the outlet when we leave the house if !presence { debug!(id = self.identifier, "Turning device off"); - set_on(self.client.clone(), self.mqtt.topic.clone(), false).await; + self.set_on(false).ok(); } } }