-
-
Notifications
You must be signed in to change notification settings - Fork 43
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 the P300 and P304 power strips
- Loading branch information
1 parent
9b1cefc
commit 9ef9727
Showing
53 changed files
with
818 additions
and
250 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"""P300 and P304 Example""" | ||
|
||
import asyncio | ||
import os | ||
|
||
from tapo import ApiClient | ||
|
||
|
||
async def main(): | ||
tapo_username = os.getenv("TAPO_USERNAME") | ||
tapo_password = os.getenv("TAPO_PASSWORD") | ||
ip_address = os.getenv("IP_ADDRESS") | ||
|
||
client = ApiClient(tapo_username, tapo_password) | ||
power_strip = await client.p300(ip_address) | ||
|
||
device_info = await power_strip.get_device_info() | ||
print(f"Device info: {device_info.to_dict()}") | ||
|
||
child_device_list = await power_strip.get_child_device_list() | ||
|
||
for child in child_device_list: | ||
print( | ||
"Found plug with nickname: {}, id: {}, state: {}.".format( | ||
child.nickname, | ||
child.device_id, | ||
child.device_on, | ||
) | ||
) | ||
|
||
plug = await power_strip.plug(device_id=child.device_id) | ||
|
||
print("Turning device on...") | ||
await plug.on() | ||
|
||
print("Waiting 2 seconds...") | ||
await asyncio.sleep(2) | ||
|
||
print("Turning device off...") | ||
await plug.off() | ||
|
||
print("Waiting 2 seconds...") | ||
await asyncio.sleep(2) | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
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,13 +1,13 @@ | ||
[tool.poetry] | ||
name = "tapo" | ||
version = "0.5.1" | ||
description = "Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L535, L610, L630), plugs (P100, P105, P110, P115), 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), plugs (P100, P105, P110, P115), power strips (P300, P304), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315)." | ||
authors = ["Mihai Dinculescu <[email protected]>"] | ||
|
||
[project] | ||
name = "tapo" | ||
version = "0.5.1" | ||
description = "Unofficial Tapo API Client. Works with TP-Link Tapo smart devices. Tested with light bulbs (L510, L520, L530, L535, L610, L630), plugs (P100, P105, P110, P115), 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), plugs (P100, P105, P110, P115), power strips (P300, P304), hubs (H100), switches (S200B) and sensors (KE100, T100, T110, T300, T310, T315)." | ||
readme = "README.md" | ||
license = { file = "LICENSE" } | ||
authors = [ | ||
|
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
46 changes: 46 additions & 0 deletions
46
tapo-py/src/handlers/child_devices/power_strip_plug_handler.rs
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
use std::{ops::Deref, sync::Arc}; | ||
|
||
use pyo3::{prelude::*, types::PyDict}; | ||
use tapo::responses::PowerStripPlugResult; | ||
use tapo::PowerStripPlugHandler; | ||
|
||
use crate::call_handler_method; | ||
|
||
#[derive(Clone)] | ||
#[pyclass(name = "PowerStripPlugHandler")] | ||
pub struct PyPowerStripPlugHandler { | ||
handler: Arc<PowerStripPlugHandler>, | ||
} | ||
|
||
impl PyPowerStripPlugHandler { | ||
pub fn new(handler: PowerStripPlugHandler) -> Self { | ||
Self { | ||
handler: Arc::new(handler), | ||
} | ||
} | ||
} | ||
|
||
#[pymethods] | ||
impl PyPowerStripPlugHandler { | ||
pub async fn get_device_info(&self) -> PyResult<PowerStripPlugResult> { | ||
let handler = self.handler.clone(); | ||
call_handler_method!(handler.deref(), PowerStripPlugHandler::get_device_info) | ||
} | ||
|
||
pub async fn get_device_info_json(&self) -> PyResult<Py<PyDict>> { | ||
let handler = self.handler.clone(); | ||
let result = | ||
call_handler_method!(handler.deref(), PowerStripPlugHandler::get_device_info_json)?; | ||
Python::with_gil(|py| tapo::python::serde_object_to_py_dict(py, &result)) | ||
} | ||
|
||
pub async fn on(&self) -> PyResult<()> { | ||
let handler = self.handler.clone(); | ||
call_handler_method!(handler.deref(), PowerStripPlugHandler::on) | ||
} | ||
|
||
pub async fn off(&self) -> PyResult<()> { | ||
let handler = self.handler.clone(); | ||
call_handler_method!(handler.deref(), PowerStripPlugHandler::off) | ||
} | ||
} |
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.