code cleanup + better printing

This commit is contained in:
sigil-03 2025-04-06 13:32:02 -06:00
parent e8fdbbaa45
commit 503bab511a
3 changed files with 8 additions and 4 deletions

View file

@ -17,7 +17,6 @@ impl Commands {
tokio::spawn(async move { tokio::spawn(async move {
m.get_power().await.unwrap(); m.get_power().await.unwrap();
}) })
// println!("[TODO] Power: ----W")
} }
}; };
handle.await.unwrap(); handle.await.unwrap();

View file

@ -41,8 +41,6 @@ impl Monitor {
pub fn new_from_file(config_file: &str) -> Result<Self, Error> { pub fn new_from_file(config_file: &str) -> Result<Self, Error> {
let config_str = fs::read_to_string(config_file)?; let config_str = fs::read_to_string(config_file)?;
let config: MonitorConfig = toml::from_str(&config_str)?; let config: MonitorConfig = toml::from_str(&config_str)?;
config.print();
Ok(Self { Ok(Self {
targets: Monitor::load_targets(&config.targets), targets: Monitor::load_targets(&config.targets),
client: Client::new(), client: Client::new(),
@ -60,7 +58,9 @@ impl Monitor {
pub async fn get_power(&self) -> Result<(), Error> { pub async fn get_power(&self) -> Result<(), Error> {
for target in &self.targets { for target in &self.targets {
if let Ok(res) = target.get_power().await { if let Ok(res) = target.get_power().await {
println!("POWER: {}W", res); target.print();
println!("* POWER: {}W", res);
println!("------------------")
} }
} }
Ok(()) Ok(())

View file

@ -26,11 +26,13 @@ pub struct StatusResponse {
#[derive(Deserialize, Clone)] #[derive(Deserialize, Clone)]
pub struct TasmotaInterfaceConfig { pub struct TasmotaInterfaceConfig {
name: String,
target: String, target: String,
} }
impl TasmotaInterfaceConfig { impl TasmotaInterfaceConfig {
pub fn print(&self) { pub fn print(&self) {
println!("{}", self.name);
println!("* {}", self.target); println!("* {}", self.target);
} }
} }
@ -47,6 +49,9 @@ impl TasmotaInterface {
client: Client::new(), client: Client::new(),
} }
} }
pub fn print(&self) {
println!("{}", self.config.name)
}
} }
// Monitoring // Monitoring