Crate airtouch5

Crate airtouch5 

Source
Expand description

A library to comumicate with AirTouch 5 air conditioning control consoles.

§Connecting

Use the AirTouch5::with_ipaddr() constructor to establish a connection with an AirTouch 5 console. You can use the discovery module to discover the address of a console on your local network.

let console_addr = discover().await?.address;
let at5 = AirTouch5::with_ipaddr(console_addr).await?;

§AC units

An AirTouch 5 system controls one or more air conditioning units. Each AC unit is identified by an integer index from 015 (inclusive). Use the ac_capabilities() method to list the AC units and their capabilities, or the ac_capability() method to fetch the capabilities of a single AC unit by its index.

let at5 = AirTouch5::with_ipaddr(console_addr).await?;
for (_, ac) in at5.ac_capabilities().await?.by_index() {
    println!(
        "AC unit {} supports modes {} with fan speeds {}",
        ac.name,
        ac.supported_modes.iter_names().map(|(n, _)| n).collect::<Vec<&str>>().join(", "),
        ac.supported_fan_speeds.iter_names().map(|(n, _)| n).collect::<Vec<&str>>().join(", "),
    );
}

Use the ac_status() method to get the current status of all AC units, including the current operating mode, current and target temperatures.

let at5 = AirTouch5::with_ipaddr(console_addr).await?;
for (idx, ac) in at5.ac_status().await?.acs {
    println!(
        "AC unit {} is {} targetting {}",
        idx,
        ac.power.map_or("unknown".to_string(), |x| format!("{}", x)),
        ac.setpoint.map_or("unknown".to_string(), |x| format!("{:#}", x)),
    );
}

§Zones

Each AC unit’s output may be divided into one or more zones; a zone is usually a room or set of rooms to be air conditioned as a group. Each zone is identified by an integer index. Each AC unit serves a contiguous set of zones, identified by the starting zone index and number of zones.

Use the zone_names() method to fetch the names of all zones in the system, or the zone_name() method to fetch the name of a single zone by its index.

let at5 = AirTouch5::with_ipaddr(console_addr).await?;
for (_, ac) in at5.ac_capabilities().await?.by_index() {
    let zones = future::try_join_all(
        (ac.zone_start_index..ac.zone_start_index+ac.zone_count)
            .map(|idx| at5.zone_name(idx))
        ).await?;
    println!(
        "AC unit {} serves zones {}",
        ac.name,
        zones.join(", "),
    );
}

The protcol does not specify an encoding for non-ASCII characters in zone names, and the console software appears to handle them poorly. From some experimentaion, it appears that any non-ASCII characters are first encoded as UTF-8, as one would expect, but then the encoded bytestring is truncated to the same number of bytes as there are characters in the original string. This means that, for example, a zone name with beginning with a character whose UTF-8 encoding is three bytes long, but is otherwise ASCII, will be missing the last two characters when decoded. Worse, a zone name that ends with a character whose UTF-8 encoding is more than one byte will have only its first byte present, which is invalid.

Use the zone_status() method to get the current status of all zones, including whether the zone is active, the amount of airflow to the zone, and, if the zone has a temperature sensor, the current and target temperatures.

let at5 = AirTouch5::with_ipaddr(console_addr).await?;
for (idx, zone) in at5.zone_status().await?.zones {
    println!(
        "Zone {} is {} targetting {}",
        idx,
        zone.power,
        match zone.control {
            ZoneControl::Airflow(pct) => format!("{}%", pct),
            ZoneControl::Temperature(_, t) => format!("{:#}", t),
        },
    );
}

§Subscribing to asynchronous updates

The AirTouch 5 console sends asynchronous updates when the state of the system changes (for example, a user turns the air conditioner on from the console, or the current temperature of a zone changes). Use the subscribe_changes() or subscribe_status() methods to arrange to receive such updates.

Modules§

discovery
Discover an AirTouch 5 console on the local network.
types
General public data types.

Structs§

AirTouch5
An AirTouch 5 console that we are interacting with.