Skip to main content

tapo/
lib.rs

1#![warn(missing_docs)]
2
3//! Tapo API Client.
4//!
5//! Tested with light bulbs (L510, L520, L530, L535, L610, L630), light strips (L900, L920, L930),
6//! plugs (P100, P105, P110, P110M, P115), power strips (P300, P304M, P306, P316M), hubs (H100), switches (S200B) and
7//! sensors (KE100, T100, T110, T300, T310, T315).
8//!
9//! # Example with L530
10//! ```rust,no_run
11//! use std::{env, thread, time::Duration};
12//!
13//! use tapo::{requests::Color, ApiClient};
14//!
15//! #[tokio::main]
16//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
17//!     let tapo_username = env::var("TAPO_USERNAME")?;
18//!     let tapo_password = env::var("TAPO_PASSWORD")?;
19//!     let ip_address = env::var("IP_ADDRESS")?;
20//!
21//!     let device = ApiClient::new(tapo_username, tapo_password)
22//!         .l530(ip_address)
23//!         .await?;
24//!
25//!     println!("Turning device on...");
26//!     device.on().await?;
27//!
28//!     println!("Setting the brightness to 30%...");
29//!     device.set_brightness(30).await?;
30//!
31//!     println!("Setting the color to `Chocolate`...");
32//!     device.set_color(Color::Chocolate).await?;
33//!
34//!     println!("Waiting 2 seconds...");
35//!     thread::sleep(Duration::from_secs(2));
36//!
37//!     println!("Setting the color to `Deep Sky Blue` using the `hue` and `saturation`...");
38//!     device.set_hue_saturation(195, 100).await?;
39//!
40//!     println!("Waiting 2 seconds...");
41//!     thread::sleep(Duration::from_secs(2));
42//!
43//!     println!("Setting the color to `Incandescent` using the `color temperature`...");
44//!     device.set_color_temperature(2700).await?;
45//!
46//!     println!("Waiting 2 seconds...");
47//!     thread::sleep(Duration::from_secs(2));
48//!
49//!     println!("Using the `set` API to change multiple properties in a single request...");
50//!     device
51//!         .set()
52//!         .brightness(50)
53//!         .color(Color::HotPink)
54//!         .send(&device)
55//!         .await?;
56//!
57//!     println!("Waiting 2 seconds...");
58//!     thread::sleep(Duration::from_secs(2));
59//!
60//!     println!("Turning device off...");
61//!     device.off().await?;
62//!
63//!     let device_info = device.get_device_info().await?;
64//!     println!("Device info: {device_info:?}");
65//!
66//!     let device_usage = device.get_device_usage().await?;
67//!     println!("Device usage: {device_usage:?}");
68//!
69//!     Ok(())
70//! }
71//! ```
72//!
73//! See [more examples](https://github.com/mihai-dinculescu/tapo/tree/main/tapo/examples).
74
75mod api;
76mod error;
77mod utils;
78
79#[cfg(feature = "python")]
80pub mod python;
81
82pub mod requests;
83pub mod responses;
84
85pub use api::*;
86pub use error::*;