tapo 0.9.0

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, P110M, P115), power strips (P300, P304M, P306, P316M), hubs (H100), switches (S200B, S200D, S210) and sensors (KE100, T100, T110, T300, T310, T315).
Documentation
use tokio::sync::RwLockReadGuard;

use crate::error::Error;
use crate::requests::LightSetDeviceInfoParams;
use crate::responses::{DeviceInfoLightResult, DeviceUsageEnergyMonitoringResult};

use super::{ApiClient, ApiClientExt};

tapo_handler! {
    /// Handler for the [L510](https://www.tapo.com/en/search/?q=L510),
    /// [L520](https://www.tapo.com/en/search/?q=L520) and
    /// [L610](https://www.tapo.com/en/search/?q=L610) devices.
    LightHandler(DeviceInfoLightResult),
    on_off,
    device_usage = DeviceUsageEnergyMonitoringResult,
    device_management,
}

impl LightHandler {
    /// Sets the *brightness* and turns *on* the device.
    ///
    /// # Arguments
    ///
    /// * `brightness` - between 1 and 100
    pub async fn set_brightness(&self, brightness: u8) -> Result<(), Error> {
        let client = RwLockReadGuard::map(
            self.client.read().await,
            |client: &ApiClient| -> &dyn ApiClientExt { client },
        );

        LightSetDeviceInfoParams::new(client)
            .brightness(brightness)
            .send()
            .await
    }
}