use std::{net::IpAddr, str::FromStr};
use airtouch5::{
types::{
control::{ZoneControl, ZoneControlType, ZoneControlValue},
status::ZoneSensorReading,
Temperature,
},
AirTouch5,
};
use simplelog::TermLogger;
const USAGE_STR: &str = "Usage: nineteen <ip>";
const CONTROL_NINETEEN: ZoneControl = ZoneControl {
power: None,
control: Some(ZoneControlType::Temperature),
value: Some(ZoneControlValue::Temperature(Temperature::from_deci(190))),
};
#[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 status = controller
.zone_status()
.await
.expect("could not get zone status");
let zones = status
.zones
.iter()
.filter(|(_, z)| z.sensor_reading != ZoneSensorReading::NoSensor)
.map(|(i, _)| (*i, CONTROL_NINETEEN));
let status = controller
.control_zones(zones)
.await
.expect("could not set zone control");
assert!(status.zones.values().all(|z| match z.control {
airtouch5::types::status::ZoneControl::Temperature(_, t)
if t == Temperature::from_deci(190) =>
true,
_ => false,
}));
}