airtouch5 0.2.0

A library for communicating with AirTouch 5 air conditioning system control consoles
Documentation
//! Toggle the first AC unit on or off.
//!
//! Usage:
//!     `toggle <ip>`
//!
//! Sets the first AC unit on if it's currently off, or vica versa.

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

use airtouch5::{
    types::control::{AcControl, AcPower},
    AirTouch5,
};
use simplelog::TermLogger;

const USAGE_STR: &str = "Usage: toggle <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");

    // send the control request
    let _status = controller
        .control_ac(
            0,
            AcControl {
                power: Some(AcPower::Toggle),
                mode: None,
                fan_speed: None,
                setpoint: None,
            },
        )
        .await
        .expect("could not set ac control");
}