code cleanup + better printing
This commit is contained in:
parent
e8fdbbaa45
commit
503bab511a
3 changed files with 8 additions and 4 deletions
|
|
@ -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();
|
||||||
|
|
|
||||||
|
|
@ -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(())
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue