use std::{net::IpAddr, str::FromStr, sync::LazyLock};
use airtouch5::AirTouch5;
use simplelog::TermLogger;
const USAGE_STR: &str = "Usage: status <ip>";
static UNNAMED_ZONE: LazyLock<String> = LazyLock::new(|| "<unknown>".to_string());
#[tokio::main(flavor = "current_thread")]
pub async fn main() {
TermLogger::init(
log::LevelFilter::Debug,
simplelog::Config::default(),
simplelog::TerminalMode::Mixed,
simplelog::ColorChoice::Auto,
)
.expect("could non init logger");
let addr = IpAddr::from_str(&std::env::args().nth(1).expect(USAGE_STR)).expect(USAGE_STR);
let controller = AirTouch5::with_ipaddr(addr)
.await
.expect("could not connect");
let acs = controller
.ac_status()
.await
.expect("could not get AC status");
for (_, ac) in acs.acs {
println!("{}", ac);
}
println!();
let names = controller
.zone_names()
.await
.expect("could not get zone names");
let w = names.by_index().map(|(_, z)| z.len()).max().unwrap_or(0);
let status = controller
.zone_status()
.await
.expect("could not get zone status");
for (idx, s) in status.zones {
println!(
"{:>w$}: {}",
names.zones.get(&idx).unwrap_or(&UNNAMED_ZONE),
s
);
}
}