Skip to main content

ApiClient

Struct ApiClient 

Source
pub struct ApiClient { /* private fields */ }
Expand description

Tapo API Client. See examples.

§Example

use tapo::ApiClient;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l530("192.168.1.100")
    .await?;

    device.on().await?;

    Ok(())
}

Implementations§

Source§

impl ApiClient

Tapo API Client constructor.

Source

pub fn new( tapo_username: impl Into<String>, tapo_password: impl Into<String>, ) -> ApiClient

Returns a new instance of ApiClient. 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 reqwest::Client.

§Arguments
  • tapo_username - the Tapo username
  • tapo_password - the Tapo password

Note: The default connection timeout is 30 seconds. Use ApiClient::with_timeout to change it.

Source

pub fn with_timeout(self, timeout: Duration) -> ApiClient

Changes the connection timeout from the default value to the given value.

§Arguments
  • timeout - The new connection timeout value.
Source

pub async fn discover_devices( self, target: impl Into<String>, timeout_s: u64, ) -> Result<DeviceDiscovery, Error>

Discovers one or more devices located at a specified unicast or broadcast IP address.

§Arguments
  • target - The IP address at which the discovery will take place. This address can be either a unicast (e.g. 192.168.1.10) or a broadcast address (e.g. 192.168.1.255, 255.255.255.255, etc.).
  • timeout_s - The maximum time to wait for a response from the device(s) in seconds. Must be between 1 and 60.
Source§

impl ApiClient

Device handler builders.

Source

pub async fn generic_device( self, ip_address: impl Into<String>, ) -> Result<GenericDeviceHandler, Error>

Specializes the given ApiClient into an authenticated GenericDeviceHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .generic_device("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l510( self, ip_address: impl Into<String>, ) -> Result<LightHandler, Error>

Specializes the given ApiClient into an authenticated LightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l510("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l520( self, ip_address: impl Into<String>, ) -> Result<LightHandler, Error>

Specializes the given ApiClient into an authenticated LightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l520("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l530( self, ip_address: impl Into<String>, ) -> Result<ColorLightHandler, Error>

Specializes the given ApiClient into an authenticated ColorLightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l530("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l535( self, ip_address: impl Into<String>, ) -> Result<ColorLightHandler, Error>

Specializes the given ApiClient into an authenticated ColorLightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l535("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l610( self, ip_address: impl Into<String>, ) -> Result<LightHandler, Error>

Specializes the given ApiClient into an authenticated LightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l610("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l630( self, ip_address: impl Into<String>, ) -> Result<ColorLightHandler, Error>

Specializes the given ApiClient into an authenticated ColorLightHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l630("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l900( self, ip_address: impl Into<String>, ) -> Result<RgbLightStripHandler, Error>

Specializes the given ApiClient into an authenticated RgbLightStripHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l900("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l920( self, ip_address: impl Into<String>, ) -> Result<RgbicLightStripHandler, Error>

Specializes the given ApiClient into an authenticated RgbicLightStripHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l920("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn l930( self, ip_address: impl Into<String>, ) -> Result<RgbicLightStripHandler, Error>

Specializes the given ApiClient into an authenticated RgbicLightStripHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .l930("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn p100( self, ip_address: impl Into<String>, ) -> Result<PlugHandler, Error>

Specializes the given ApiClient into an authenticated PlugHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p100("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn p105( self, ip_address: impl Into<String>, ) -> Result<PlugHandler, Error>

Specializes the given ApiClient into an authenticated PlugHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p105("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn p110( self, ip_address: impl Into<String>, ) -> Result<PlugEnergyMonitoringHandler, Error>

Specializes the given ApiClient into an authenticated PlugEnergyMonitoringHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p110("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn p115( self, ip_address: impl Into<String>, ) -> Result<PlugEnergyMonitoringHandler, Error>

Specializes the given ApiClient into an authenticated PlugEnergyMonitoringHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p115("192.168.1.100")
    .await?;
device.on().await?;
Source

pub async fn p300( self, ip_address: impl Into<String>, ) -> Result<PowerStripHandler, Error>

Specializes the given ApiClient into an authenticated PowerStripHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p300("192.168.1.100")
    .await?;
let child_device_list = device.get_child_device_list().await?;
println!("Child device list: {child_device_list:?}");
Source

pub async fn p304( self, ip_address: impl Into<String>, ) -> Result<PowerStripEnergyMonitoringHandler, Error>

Specializes the given ApiClient into an authenticated PowerStripEnergyMonitoringHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
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:?}");
Source

pub async fn p306( self, ip_address: impl Into<String>, ) -> Result<PowerStripHandler, Error>

Specializes the given ApiClient into an authenticated PowerStripHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p306("192.168.1.100")
    .await?;
let child_device_list = device.get_child_device_list().await?;
println!("Child device list: {child_device_list:?}");
Source

pub async fn p316( self, ip_address: impl Into<String>, ) -> Result<PowerStripEnergyMonitoringHandler, Error>

Specializes the given ApiClient into an authenticated PowerStripEnergyMonitoringHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .p316("192.168.1.100")
    .await?;
let child_device_list = device.get_child_device_list().await?;
println!("Child device list: {child_device_list:?}");
Source

pub async fn h100( self, ip_address: impl Into<String>, ) -> Result<HubHandler, Error>

Specializes the given ApiClient into an authenticated HubHandler.

§Arguments
  • ip_address - the IP address of the device
§Example
let device = ApiClient::new("tapo-username@example.com", "tapo-password")
    .h100("192.168.1.100")
    .await?;

let child_device_list = device.get_child_device_list().await?;
println!("Child device list: {child_device_list:?}");

Trait Implementations§

Source§

impl ApiClientExt for ApiClient

Source§

fn set_device_info<'life0, 'async_trait>( &'life0 self, device_info_params: Value, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Sets device info by sending the given parameters.
Source§

fn device_reboot<'life0, 'async_trait>( &'life0 self, delay: u16, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Reboots the device.
Source§

fn device_reset<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Hardware resets the device.
Source§

impl Clone for ApiClient

Source§

fn clone(&self) -> ApiClient

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ApiClient

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more