Skip to content

Commit

Permalink
changing timeout API to use set_timeout function on the ApiClient
Browse files Browse the repository at this point in the history
  • Loading branch information
skoky committed Mar 2, 2024
1 parent 576853e commit a4bb989
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions tapo/examples/tapo_p100.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let ip_address = env::var("IP_ADDRESS")?;

let device = ApiClient::new(tapo_username, tapo_password)
.set_timeout(Duration::from_secs(3))
.p100(ip_address)
.await?;

Expand Down
14 changes: 13 additions & 1 deletion tapo/src/api/api_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,15 @@ pub struct ApiClient {
/// Tapo API Client constructor.
impl ApiClient {
/// Returns a new instance of [`ApiClient`].
/// It it cheaper to [`ApiClient::clone`] an existing instance than to create a new one when multiple devices need to be controller.
/// It is cheaper to [`ApiClient::clone`] an existing instance than to create a new one when multiple devices need to be controller.
/// This is because [`ApiClient::clone`] reuses the underlying [`isahc::HttpClient`] and [`openssl::rsa::Rsa`] key.
///
/// # Arguments
///
/// * `tapo_username` - the Tapo username
/// * `tapo_password` - the Tapo password
///
/// Note: uses default connection timeout value of 30 secs
pub fn new(tapo_username: impl Into<String>, tapo_password: impl Into<String>) -> ApiClient {
Self {
tapo_username: tapo_username.into(),
Expand All @@ -75,6 +77,16 @@ impl ApiClient {
protocol: None,
}
}

/// changes connection timout from default value to new custom value
///
/// # Arguments
///
/// * `timeout` - the timeout value
pub fn set_timeout(mut self, timeout: Duration) -> ApiClient {
self.timeout = Some(timeout);
self
}
}

/// Device handler builders.
Expand Down

0 comments on commit a4bb989

Please sign in to comment.