Skip to content

Commit

Permalink
Add support for L520 and the set API to L510, L520 and L610
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-dinculescu committed Oct 30, 2023
1 parent e061147 commit 7c234ed
Show file tree
Hide file tree
Showing 13 changed files with 128 additions and 62 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ file. This change log follows the conventions of

## [Rust Unreleased][Unreleased]

### Added

- Added a dedicated handler for the L520 devices.
- Added support for the `set` API to the L510, L520 and L610 devices.

## [Python Unreleased][Unreleased]

### Changed
Expand Down
56 changes: 28 additions & 28 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
[![PyPI][pypi_badge]][pypi]
[![Python][pypi_versions_badge]][pypi]
[![PyPI][pypi_downloads_badge]][pypi]\
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).
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).

[license_badge]: https://img.shields.io/crates/l/tapo.svg
[license]: https://github.com/mihai-dinculescu/tapo/blob/main/LICENSE
Expand All @@ -28,22 +28,22 @@ Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with l
✓ - Rust only\
✅ - Rust and Python

| Feature | GenericDevice | L510, L610 | L530, L630, L900 | L920, L930 | P100, P105 | P110, P115 |
| --------------------- | ------------: | ---------: | ---------------: | ---------: | ---------: | ---------: |
| on | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| off | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_info | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_info_json | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_usage | | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_energy_usage | | | | | | ✅ |
| get_energy_data | | | | | | ✅ |
| get_current_power | | | | | | ✅ |
| set_brightness | | ✓ | ✓ | ✓ | | |
| set_color | | | ✓ | ✓ | | |
| set_hue_saturation | | | ✓ | ✓ | | |
| set_color_temperature | | | ✓ | ✓ | | |
| set_lighting_effect | | | | ✓ | | |
| set() API \* | | | ✓ | ✓ | | |
| Feature | GenericDevice | L510, L520, L610 | L530, L630, L900 | L920, L930 | P100, P105 | P110, P115 |
| --------------------- | ------------: | ---------------: | ---------------: | ---------: | ---------: | ---------: |
| on | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| off | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_info | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_info_json | ✅ | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_device_usage | | ✓ | ✓ | ✓ | ✅ | ✅ |
| get_energy_usage | | | | | | ✅ |
| get_energy_data | | | | | | ✅ |
| get_current_power | | | | | | ✅ |
| set_brightness | | ✓ | ✓ | ✓ | | |
| set_color | | | ✓ | ✓ | | |
| set_hue_saturation | | | ✓ | ✓ | | |
| set_color_temperature | | | ✓ | ✓ | | |
| set_lighting_effect | | | | ✓ | | |
| set() API \* | | ✓ | ✓ | ✓ | | |

\* The `set()` API allows multiple properties to be set in a single request.

Expand Down
4 changes: 2 additions & 2 deletions tapo-py/tapo.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Tapo API Client.
Tested with light bulbs (L510, L530, L610, L630), light strips (L900, L920, L930),
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).
Example:
Expand Down Expand Up @@ -29,7 +29,7 @@ from typing import Optional, List
class ApiClient:
"""Tapo API Client.
Tested with light bulbs (L510, L530, L610, L630), light strips (L900, L920, L930),
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).
Example:
Expand Down
2 changes: 1 addition & 1 deletion tapo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
14 changes: 11 additions & 3 deletions tapo/examples/tapo_l510.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// L510 Example
/// L510, L520 & L610 Example
use std::{env, thread, time::Duration};

use log::{info, LevelFilter};
Expand Down Expand Up @@ -26,17 +26,25 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
info!("Turning device on...");
device.on().await?;

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

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

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

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

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

info!("Turning device off...");
device.off().await?;
info!("Using the `set` API to set multiple properties in a single request...");
// By default, adjusting the brightness turns the device on,
// so we need to explicitly set it off.
device.set().brightness(50).off().send().await?;

let device_info = device.get_device_info().await?;
info!("Device info: {device_info:?}");
Expand Down
2 changes: 1 addition & 1 deletion tapo/examples/tapo_l530.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// L530 Example
/// L530, L630 & L900 Example
use std::{env, thread, time::Duration};

use log::{info, LevelFilter};
Expand Down
2 changes: 1 addition & 1 deletion tapo/examples/tapo_l930.rs
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};
Expand Down
26 changes: 26 additions & 0 deletions tapo/src/api/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion tapo/src/api/light_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tapo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

//! Tapo API Client.
//!
//! Tested with light bulbs (L510, L530, L610, L630), light strips (L900, L920, L930),
//! 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).
//!
//! # Example with L530
Expand Down
2 changes: 1 addition & 1 deletion tapo/src/requests/set_device_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ mod generic_device;
mod light;

pub use color_light::*;
pub use light::*;

pub(crate) use generic_device::*;
pub(crate) use light::*;
Loading

0 comments on commit 7c234ed

Please sign in to comment.