tapo 0.8.12

Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. 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, S200D) and sensors (KE100, T100, T110, T300, T310, T315).
Documentation
/// Toggle Generic Device Example
use std::env;

use log::{info, warn};
use tapo::ApiClient;

mod common;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    common::setup_logger();

    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)
        .generic_device(ip_address)
        .await?;

    let device_info = device.get_device_info().await?;

    match device_info.device_on {
        Some(true) => {
            info!("Device is on. Turning it off...");
            device.off().await?;
        }
        Some(false) => {
            info!("Device is off. Turning it on...");
            device.on().await?;
        }
        None => {
            warn!("This device does not support on/off functionality.");
        }
    }

    Ok(())
}