diff --git a/tapo-py/examples/tapo_p100.py b/tapo-py/examples/tapo_p100.py index b0650f6..257b4fc 100644 --- a/tapo-py/examples/tapo_p100.py +++ b/tapo-py/examples/tapo_p100.py @@ -11,7 +11,7 @@ async def main(): tapo_password = os.getenv("TAPO_PASSWORD") ip_address = os.getenv("IP_ADDRESS") - client = ApiClient(tapo_username, tapo_password, timeout_secs=3) + client = ApiClient(tapo_username, tapo_password, timeout_secs=10) device = await client.p100(ip_address) print("Turning device on...") diff --git a/tapo-py/src/api_client.rs b/tapo-py/src/api_client.rs index f6dcad4..b4352b9 100644 --- a/tapo-py/src/api_client.rs +++ b/tapo-py/src/api_client.rs @@ -1,3 +1,4 @@ +use std::time::Duration; use pyo3::prelude::*; use tapo::ApiClient; @@ -15,8 +16,9 @@ pub struct PyApiClient { #[pymethods] impl PyApiClient { #[new] - pub fn new(tapo_username: String, tapo_password: String) -> Result { - let client = ApiClient::new(tapo_username, tapo_password); + pub fn new(tapo_username: String, tapo_password: String, timeout_secs: Option) -> Result { + let client = ApiClient::new(tapo_username, tapo_password) + .with_timeout(Duration::from_secs(timeout_secs.unwrap_or(30))); Ok(Self { client }) } diff --git a/tapo/examples/tapo_p100.rs b/tapo/examples/tapo_p100.rs index 47cbecd..ea0b703 100644 --- a/tapo/examples/tapo_p100.rs +++ b/tapo/examples/tapo_p100.rs @@ -20,7 +20,7 @@ async fn main() -> Result<(), Box> { let ip_address = env::var("IP_ADDRESS")?; let device = ApiClient::new(tapo_username, tapo_password) - .set_timeout(Duration::from_secs(3)) + .with_timeout(Duration::from_secs(3)) .p100(ip_address) .await?; diff --git a/tapo/src/api/api_client.rs b/tapo/src/api/api_client.rs index 1749228..a02ac2e 100644 --- a/tapo/src/api/api_client.rs +++ b/tapo/src/api/api_client.rs @@ -83,7 +83,7 @@ impl ApiClient { /// # Arguments /// /// * `timeout` - the timeout value - pub fn set_timeout(mut self, timeout: Duration) -> ApiClient { + pub fn with_timeout(mut self, timeout: Duration) -> ApiClient { self.timeout = Some(timeout); self }