Crate tapo

Crate tapo 

Source
Expand description

Tapo API Client.

Tested with light bulbs (L510, L520, L530, L535, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P110M, P115), power strips (P300, P304M, P306, P316M), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315).

§Example with L530

use std::{env, thread, time::Duration};

use tapo::{requests::Color, ApiClient};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let tapo_username = env::var("TAPO_USERNAME")?;
    let tapo_password = env::var("TAPO_PASSWORD")?;
    let ip_address = env::var("IP_ADDRESS")?;

    let device = ApiClient::new(tapo_username, tapo_password)
        .l530(ip_address)
        .await?;

    println!("Turning device on...");
    device.on().await?;

    println!("Setting the brightness to 30%...");
    device.set_brightness(30).await?;

    println!("Setting the color to `Chocolate`...");
    device.set_color(Color::Chocolate).await?;

    println!("Waiting 2 seconds...");
    thread::sleep(Duration::from_secs(2));

    println!("Setting the color to `Deep Sky Blue` using the `hue` and `saturation`...");
    device.set_hue_saturation(195, 100).await?;

    println!("Waiting 2 seconds...");
    thread::sleep(Duration::from_secs(2));

    println!("Setting the color to `Incandescent` using the `color temperature`...");
    device.set_color_temperature(2700).await?;

    println!("Waiting 2 seconds...");
    thread::sleep(Duration::from_secs(2));

    println!("Using the `set` API to change multiple properties in a single request...");
    device
        .set()
        .brightness(50)
        .color(Color::HotPink)
        .send(&device)
        .await?;

    println!("Waiting 2 seconds...");
    thread::sleep(Duration::from_secs(2));

    println!("Turning device off...");
    device.off().await?;

    let device_info = device.get_device_info().await?;
    println!("Device info: {device_info:?}");

    let device_usage = device.get_device_usage().await?;
    println!("Device usage: {device_usage:?}");

    Ok(())
}

See more examples.

Modules§

requests
Tapo request objects.
responses
Tapo response objects.

Structs§

ApiClient
Tapo API Client. See examples.
ColorLightHandler
Handler for the L530, L535 and L630 devices.
DeviceDiscovery
Device discovery process for Tapo devices.
GenericDeviceHandler
Handler for generic devices. It provides the functionality common to all Tapo devices.
HubHandler
Handler for the H100 devices.
KE100Handler
Handler for the KE100 devices.
LightHandler
Handler for the L510, L520 and L610 devices.
PlugEnergyMonitoringHandler
Handler for the P110, P110M and P115 devices.
PlugHandler
Handler for the P100 and P105 devices.
PowerStripEnergyMonitoringHandler
Handler for the P304M and P316M devices.
PowerStripHandler
Handler for the P300 and P306 devices.
PowerStripPlugEnergyMonitoringHandler
Handler for the P304M and P316M child plugs.
PowerStripPlugHandler
Handler for the P300 and P306 child plugs.
RgbLightStripHandler
Handler for the L900 devices.
RgbicLightStripHandler
Handler for the L920 and L930 devices.
S200BHandler
Handler for the S200B devices.
T31XHandler
Handler for the T310 and T315 devices.
T100Handler
Handler for the T100 devices.
T110Handler
Handler for the T110 devices.
T300Handler
Handler for the T300 devices.

Enums§

DiscoveryResult
Result of the device discovery process.
Error
Tapo API Client Error.
HubDevice
Hub Device.
Plug
Power strip plug.
TapoResponseError
Response Error from the Tapo API.

Traits§

ApiClientExt
Implemented by all ApiClient implementations.
DeviceManagementExt
Extension trait for device management capabilities like device_reboot and device_reset.
HandlerExt
Implemented by all device handlers.
StreamExt
An extension trait for the Stream trait that provides a variety of convenient combinator functions.