From 503bab511a147400f3e8878e9a924974f65c7fa6 Mon Sep 17 00:00:00 2001 From: sigil-03 Date: Sun, 6 Apr 2025 13:32:02 -0600 Subject: [PATCH] code cleanup + better printing --- src/main.rs | 1 - src/monitor.rs | 6 +++--- src/tasmota.rs | 5 +++++ 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 73f1b28..129371c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,6 @@ impl Commands { tokio::spawn(async move { m.get_power().await.unwrap(); }) - // println!("[TODO] Power: ----W") } }; handle.await.unwrap(); diff --git a/src/monitor.rs b/src/monitor.rs index dec5afd..c43974a 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -41,8 +41,6 @@ impl Monitor { pub fn new_from_file(config_file: &str) -> Result { let config_str = fs::read_to_string(config_file)?; let config: MonitorConfig = toml::from_str(&config_str)?; - config.print(); - Ok(Self { targets: Monitor::load_targets(&config.targets), client: Client::new(), @@ -60,7 +58,9 @@ impl Monitor { pub async fn get_power(&self) -> Result<(), Error> { for target in &self.targets { if let Ok(res) = target.get_power().await { - println!("POWER: {}W", res); + target.print(); + println!("* POWER: {}W", res); + println!("------------------") } } Ok(()) diff --git a/src/tasmota.rs b/src/tasmota.rs index dcc010b..1ad6f5b 100644 --- a/src/tasmota.rs +++ b/src/tasmota.rs @@ -26,11 +26,13 @@ pub struct StatusResponse { #[derive(Deserialize, Clone)] pub struct TasmotaInterfaceConfig { + name: String, target: String, } impl TasmotaInterfaceConfig { pub fn print(&self) { + println!("{}", self.name); println!("* {}", self.target); } } @@ -47,6 +49,9 @@ impl TasmotaInterface { client: Client::new(), } } + pub fn print(&self) { + println!("{}", self.config.name) + } } // Monitoring