From 79a40750ff2456a719e1fbd469e981f07cb2bd74 Mon Sep 17 00:00:00 2001 From: Mihai Dinculescu Date: Tue, 8 Oct 2024 23:35:16 +0100 Subject: [PATCH] Add support for the P304 power strip --- CHANGELOG.md | 8 +++- README.md | 44 +++++++++---------- tapo/Cargo.toml | 2 +- tapo/examples/tapo_p300.rs | 2 +- tapo/src/api/api_client.rs | 26 +++++++++++ tapo/src/api/power_strip_handler.rs | 3 +- tapo/src/lib.rs | 2 +- .../device_info_result/power_strip.rs | 2 +- 8 files changed, 60 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0136cac..4e7591f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ file. This change log follows the conventions of ## [Rust Unreleased][Unreleased] +### Added + +- Added support for the P304 power strip. + ## [Python Unreleased][Unreleased] ## [Rust v0.7.16][v0.7.16] - 2024-09-27 @@ -16,7 +20,7 @@ file. This change log follows the conventions of ### Fixed -- Fixed an issue that was preventing the color from being set properly to the L535 light bulbs. +- Fixed an issue that prevented the color from being set properly for the L535 light bulbs. ## [Python v0.5.1][py-v0.5.1] - 2024-09-27 @@ -26,7 +30,7 @@ file. This change log follows the conventions of ### Fixed -- Fixed an issue that was preventing the color from being set properly to the L535 light bulbs. +- Fixed an issue that prevented the color from being set properly for the L535 light bulbs. ## [Rust v0.7.15][v0.7.15] - 2024-09-18 diff --git a/README.md b/README.md index 9fbdea8..cd5833a 100644 --- a/README.md +++ b/README.md @@ -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, L520, L530, L535, L610, L630), light strips (L900, L920, L930), plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315). +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, P115), power strips (P300, P304), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315). [license_badge]: https://img.shields.io/crates/l/tapo.svg [license]: https://github.com/mihai-dinculescu/tapo/blob/main/LICENSE @@ -28,27 +28,27 @@ Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with l ✓ - Rust only\ ✅ - Rust and Python -| Feature


| GenericDevice


| L510
L520
L610 | L530
L535
L630
| L900


| L920
L930

| P100
P105

| P110
P115

| P300


| H100


| -| ------------------------------------ | :--------------------------: | :--------------------: | :-------------------------: | :-----------------: | :---------------------: | :---------------------: | :---------------------: | :-----------------: | :-----------------: | -| device_reset | | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | -| get_child_device_component_list_json | | | | | | | | ✓ | ✅ | -| get_child_device_list | | | | | | | | ✓ | ✅ | -| get_child_device_list_json | | | | | | | | ✓ | ✅ | -| get_current_power | | | | | | | ✅ | | | -| get_device_info | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | -| get_device_info_json | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | -| get_device_usage | | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | -| get_energy_data | | | | | | | ✅ | | | -| get_energy_usage | | | | | | | ✅ | | | -| off | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | -| on | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | -| refresh_session | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | -| set_brightness | | ✅ | ✅ | ✓ | ✓ | | | | | -| set_color | | | ✅ | ✓ | ✓ | | | | | -| set_color_temperature | | | ✅ | ✓ | ✓ | | | | | -| set_hue_saturation | | | ✅ | ✓ | ✓ | | | | | -| set_lighting_effect | | | | | ✓ | | | | | -| set() API \* | | | ✅ | ✓ | ✓ | | | | | +| Feature


| GenericDevice


| L510
L520
L610 | L530
L535
L630
| L900


| L920
L930

| P100
P105

| P110
P115

| P300
P304

| H100


| +| ------------------------------------ | :--------------------------: | :--------------------: | :-------------------------: | :-----------------: | :---------------------: | :---------------------: | :---------------------: | :---------------------: | :-----------------: | +| device_reset | | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | +| get_child_device_component_list_json | | | | | | | | ✓ | ✅ | +| get_child_device_list | | | | | | | | ✓ | ✅ | +| get_child_device_list_json | | | | | | | | ✓ | ✅ | +| get_current_power | | | | | | | ✅ | | | +| get_device_info | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | +| get_device_info_json | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | +| get_device_usage | | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | +| get_energy_data | | | | | | | ✅ | | | +| get_energy_usage | | | | | | | ✅ | | | +| off | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | +| on | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | | | +| refresh_session | ✅ | ✅ | ✅ | ✓ | ✓ | ✅ | ✅ | ✓ | ✅ | +| set_brightness | | ✅ | ✅ | ✓ | ✓ | | | | | +| set_color | | | ✅ | ✓ | ✓ | | | | | +| set_color_temperature | | | ✅ | ✓ | ✓ | | | | | +| set_hue_saturation | | | ✅ | ✓ | ✓ | | | | | +| set_lighting_effect | | | | | ✓ | | | | | +| set() API \* | | | ✅ | ✓ | ✓ | | | | | \* The `set()` API allows multiple properties to be set in a single request. diff --git a/tapo/Cargo.toml b/tapo/Cargo.toml index 68930d3..3237ef4 100644 --- a/tapo/Cargo.toml +++ b/tapo/Cargo.toml @@ -4,7 +4,7 @@ version = "0.7.16" edition = "2021" license = "MIT" authors = ["Mihai Dinculescu "] -description = "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, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315)." +description = "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, P115), power strips (P300, P304), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315)." keywords = ["IOT", "tapo", "smart-home", "smart-bulb", "smart-plug"] categories = ["hardware-support", "embedded", "development-tools"] readme = "README.md" diff --git a/tapo/examples/tapo_p300.rs b/tapo/examples/tapo_p300.rs index ad5ea46..44f2521 100644 --- a/tapo/examples/tapo_p300.rs +++ b/tapo/examples/tapo_p300.rs @@ -1,4 +1,4 @@ -/// P300 Example +/// P300 and P304 Example use std::{env, thread, time::Duration}; use log::{info, LevelFilter}; diff --git a/tapo/src/api/api_client.rs b/tapo/src/api/api_client.rs index 497c24a..803f380 100644 --- a/tapo/src/api/api_client.rs +++ b/tapo/src/api/api_client.rs @@ -457,6 +457,32 @@ impl ApiClient { Ok(PowerStripHandler::new(self)) } + /// Specializes the given [`ApiClient`] into an authenticated [`PowerStripHandler`]. + /// + /// # Arguments + /// + /// * `ip_address` - the IP address of the device + /// + /// # Example + /// + /// ```rust,no_run + /// # use tapo::ApiClient; + /// # #[tokio::main] + /// # async fn main() -> Result<(), Box> { + /// let device = ApiClient::new("tapo-username@example.com", "tapo-password") + /// .p304("192.168.1.100") + /// .await?; + /// let child_device_list = device.get_child_device_list().await?; + /// println!("Child device list: {child_device_list:?}"); + /// # Ok(()) + /// # } + /// ``` + pub async fn p304(mut self, ip_address: impl Into) -> Result { + self.login(ip_address).await?; + + Ok(PowerStripHandler::new(self)) + } + /// Specializes the given [`ApiClient`] into an authenticated [`PlugEnergyMonitoringHandler`]. /// /// # Arguments diff --git a/tapo/src/api/power_strip_handler.rs b/tapo/src/api/power_strip_handler.rs index 8a930b6..9cc438c 100644 --- a/tapo/src/api/power_strip_handler.rs +++ b/tapo/src/api/power_strip_handler.rs @@ -9,7 +9,8 @@ use crate::responses::{ ChildDeviceListPowerStripResult, DeviceInfoPowerStripResult, PlugPowerStripResult, }; -/// Handler for the [P300](https://www.tapo.com/en/search/?q=P300) devices. +/// Handler for the [P300](https://www.tapo.com/en/search/?q=P300) and +/// [P304](https://www.tp-link.com/uk/search/?q=P304) devices. pub struct PowerStripHandler { client: Arc>, } diff --git a/tapo/src/lib.rs b/tapo/src/lib.rs index ce9ee16..abf4a03 100644 --- a/tapo/src/lib.rs +++ b/tapo/src/lib.rs @@ -3,7 +3,7 @@ //! Tapo API Client. //! //! Tested with light bulbs (L510, L520, L530, L535, L610, L630), light strips (L900, L920, L930), -//! plugs (P100, P105, P110, P115, P300), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315). +//! plugs (P100, P105, P110, P115), power strips (P300, P304), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315). //! //! # Example with L530 //! ```rust,no_run diff --git a/tapo/src/responses/device_info_result/power_strip.rs b/tapo/src/responses/device_info_result/power_strip.rs index 238e4ca..f72bd83 100644 --- a/tapo/src/responses/device_info_result/power_strip.rs +++ b/tapo/src/responses/device_info_result/power_strip.rs @@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize}; use crate::error::Error; use crate::responses::{decode_value, DecodableResultExt, TapoResponseExt}; -/// Device info of Tapo H100. Superset of [`crate::responses::DeviceInfoGenericResult`]. +/// Device info of Tapo P300 and P304. Superset of [`crate::responses::DeviceInfoGenericResult`]. #[derive(Debug, Clone, Serialize, Deserialize)] #[allow(missing_docs)] pub struct DeviceInfoPowerStripResult {