airtouch5 0.2.0

A library for communicating with AirTouch 5 air conditioning system control consoles
Documentation
//! List the zones of an AirTouch 5 controller
//!
//! Usage:
//!     `zonelist <ip>`
//!
//! Fetches the list of zones from the AirTouch 5 controller at `ip`, and
//! prints their name and zone index in lexical order.

use std::{net::IpAddr, str::FromStr};

use airtouch5::AirTouch5;
use simplelog::TermLogger;

const USAGE_STR: &str = "Usage: zonelist <ip>";

#[tokio::main(flavor = "current_thread")]
pub async fn main() {
    // log to console
    TermLogger::init(
        log::LevelFilter::Debug,
        simplelog::Config::default(),
        simplelog::TerminalMode::Mixed,
        simplelog::ColorChoice::Auto,
    )
    .expect("could non init logger");

    // connect to the given addess
    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");

    // fetch the list of zone names
    let names = controller
        .zone_names()
        .await
        .expect("could not get zone names");

    for (idx, name) in names.by_name() {
        println!("{} (#{})", name, idx);
    }
}