Switched to tracing
This commit is contained in:
@@ -4,7 +4,7 @@ use google_home::errors::ErrorCode;
|
||||
use google_home::{GoogleHomeDevice, device, types::Type, traits};
|
||||
use rumqttc::{AsyncClient, Publish};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use log::{debug, trace, warn};
|
||||
use tracing::{debug, trace, warn};
|
||||
use tokio::task::JoinHandle;
|
||||
|
||||
use crate::config::{KettleConfig, InfoConfig, MqttDeviceConfig};
|
||||
@@ -79,7 +79,7 @@ impl OnMqtt for IkeaOutlet {
|
||||
let new_state = match StateMessage::try_from(message) {
|
||||
Ok(state) => state,
|
||||
Err(err) => {
|
||||
warn!("Failed to parse message: {err}");
|
||||
warn!(id = self.identifier, "Failed to parse message: {err}");
|
||||
return;
|
||||
}
|
||||
}.state == "ON";
|
||||
@@ -94,7 +94,7 @@ impl OnMqtt for IkeaOutlet {
|
||||
handle.abort();
|
||||
}
|
||||
|
||||
trace!("Updating state: {} => {}", self.last_known_state, new_state);
|
||||
debug!(id = self.identifier, "Updating state to {new_state}");
|
||||
self.last_known_state = new_state;
|
||||
|
||||
// If this is a kettle start a timeout for turning it of again
|
||||
@@ -107,7 +107,7 @@ impl OnMqtt for IkeaOutlet {
|
||||
let timeout = match kettle.timeout.clone() {
|
||||
Some(timeout) => timeout,
|
||||
None => {
|
||||
trace!("Outlet is a kettle without timeout");
|
||||
trace!(id = self.identifier, "Outlet is a kettle without timeout");
|
||||
return;
|
||||
},
|
||||
};
|
||||
@@ -117,16 +117,17 @@ impl OnMqtt for IkeaOutlet {
|
||||
// get dropped
|
||||
let client = self.client.clone();
|
||||
let topic = self.mqtt.topic.clone();
|
||||
let id = self.identifier.clone();
|
||||
self.handle = Some(
|
||||
tokio::spawn(async move {
|
||||
debug!("Starting timeout ({timeout}s) for kettle...");
|
||||
debug!(id, "Starting timeout ({timeout}s) for kettle...");
|
||||
tokio::time::sleep(Duration::from_secs(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!("Turning kettle off!");
|
||||
debug!(id, "Turning kettle off!");
|
||||
set_on(client, topic, false).await;
|
||||
})
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -135,10 +136,11 @@ impl OnPresence for IkeaOutlet {
|
||||
fn on_presence(&mut self, presence: bool) {
|
||||
// Turn off the outlet when we leave the house
|
||||
if !presence {
|
||||
debug!(id = self.identifier, "Turning device off");
|
||||
let client = self.client.clone();
|
||||
let topic = self.mqtt.topic.clone();
|
||||
tokio::spawn(async move {
|
||||
set_on(client, topic, false).await;
|
||||
set_on(client, topic, false).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use google_home::{GoogleHomeDevice, types::Type, device, traits::{self, Scene}, errors::{ErrorCode, DeviceError}};
|
||||
use log::{debug, warn};
|
||||
use tracing::{debug, warn};
|
||||
use rumqttc::{AsyncClient, Publish};
|
||||
use serde::Deserialize;
|
||||
|
||||
@@ -56,7 +56,7 @@ impl OnMqtt for WakeOnLAN {
|
||||
let payload = match StateMessage::try_from(message) {
|
||||
Ok(state) => state,
|
||||
Err(err) => {
|
||||
warn!("Failed to parse message: {err}");
|
||||
warn!(id = self.identifier, "Failed to parse message: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -96,23 +96,24 @@ impl traits::Scene for WakeOnLAN {
|
||||
// @TODO In the future send the wake on lan package directly, this is kind of annoying
|
||||
// if we are inside of docker, so for now just call a webhook that does it for us
|
||||
let mac_address = self.mac_address.clone();
|
||||
let id = self.identifier.clone();
|
||||
tokio::spawn(async move {
|
||||
debug!("Activating Computer: {}", mac_address);
|
||||
debug!(id, "Activating Computer: {}", mac_address);
|
||||
let req = match reqwest::get(format!("http://10.0.0.2:9000/start-pc?mac={mac_address}")).await {
|
||||
Ok(req) => req,
|
||||
Err(err) => {
|
||||
warn!("Failed to call webhook: {err}");
|
||||
warn!(id, "Failed to call webhook: {err}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
if req.status() != 200 {
|
||||
warn!("Failed to call webhook: {}", req.status());
|
||||
warn!(id, "Failed to call webhook: {}", req.status());
|
||||
}
|
||||
});
|
||||
|
||||
Ok(())
|
||||
} else {
|
||||
debug!("Trying to deactive computer, this is not currently supported");
|
||||
debug!(id = self.identifier, "Trying to deactive computer, this is not currently supported");
|
||||
// We do not support deactivating this scene
|
||||
Err(ErrorCode::DeviceError(DeviceError::ActionNotAvailable))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user