-
-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for L520 and the set API to L510, L520 and L610
- Loading branch information
1 parent
e061147
commit 7c234ed
Showing
13 changed files
with
128 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ version = "0.7.4" | |
edition = "2021" | ||
license = "MIT" | ||
authors = ["Mihai Dinculescu <[email protected]>"] | ||
description = "Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115), hubs (H100), switches (S200B) and sensors (T100, T110, T310, T315)." | ||
description = "Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115), hubs (H100), switches (S200B) and sensors (T100, T110, T310, T315)." | ||
keywords = ["IOT", "tapo", "smart-home", "smart-bulb", "smart-plug"] | ||
categories = ["hardware-support", "embedded", "development-tools"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
/// L930 Example | ||
/// L920 & L930 Example | ||
use std::{env, thread, time::Duration}; | ||
|
||
use log::{info, LevelFilter}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -155,6 +155,32 @@ impl ApiClient { | |
Ok(ColorLightHandler::new(self)) | ||
} | ||
|
||
/// Specializes the given [`ApiClient`] into an authenticated [`LightHandler`]. | ||
/// | ||
/// # Arguments | ||
/// | ||
/// * `ip_address` - the IP address of the device | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust,no_run | ||
/// # use tapo::ApiClient; | ||
/// # #[tokio::main] | ||
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
/// let device = ApiClient::new("[email protected]", "tapo-password")? | ||
/// .l520("192.168.1.100") | ||
/// .await?; | ||
/// device.on().await?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub async fn l520(mut self, ip_address: impl Into<String>) -> Result<LightHandler, Error> { | ||
let url = build_url(&ip_address.into()); | ||
self.login(url).await?; | ||
|
||
Ok(LightHandler::new(self)) | ||
} | ||
|
||
/// Specializes the given [`ApiClient`] into an authenticated [`LightHandler`]. | ||
/// | ||
/// # Arguments | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,8 @@ use crate::error::Error; | |
use crate::requests::LightSetDeviceInfoParams; | ||
use crate::responses::{DeviceInfoLightResult, DeviceUsageEnergyMonitoringResult}; | ||
|
||
/// Handler for the [L510](https://www.tapo.com/en/search/?q=L510) and [L610](https://www.tapo.com/en/search/?q=L610) devices. | ||
/// Handler for the [L510](https://www.tapo.com/en/search/?q=L510), [L520](https://www.tapo.com/en/search/?q=L520) | ||
/// and [L610](https://www.tapo.com/en/search/?q=L610) devices. | ||
pub struct LightHandler { | ||
client: ApiClient, | ||
} | ||
|
@@ -53,6 +54,32 @@ impl LightHandler { | |
self.client.get_device_usage().await | ||
} | ||
|
||
/// Returns a [`LightSetDeviceInfoParams`] builder that allows multiple properties to be set in a single request. | ||
/// [`LightSetDeviceInfoParams::send`] must be called at the end to apply the changes. | ||
/// | ||
/// # Example | ||
/// | ||
/// ```rust,no_run | ||
/// # use tapo::ApiClient; | ||
/// # use tapo::requests::Color; | ||
/// # #[tokio::main] | ||
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
/// # let device = ApiClient::new("[email protected]", "tapo-password")? | ||
/// # .l510("192.168.1.100") | ||
/// # .await?; | ||
/// device | ||
/// .set() | ||
/// .brightness(50) | ||
/// .off() | ||
/// .send() | ||
/// .await?; | ||
/// # Ok(()) | ||
/// # } | ||
/// ``` | ||
pub fn set(&self) -> LightSetDeviceInfoParams { | ||
LightSetDeviceInfoParams::new(&self.client) | ||
} | ||
|
||
/// Sets the *brightness* and turns *on* the device. | ||
/// | ||
/// # Arguments | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.