1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
use crate::tapo_vendor::error::Error;
use crate::tapo_vendor::requests::{SendIrCmdByIdParams, TapoParams, TapoRequest};
use crate::tapo_vendor::responses::IrRemoteResult;
tapo_child_handler! {
/// Handler for the IR remotes paired with a
/// [H110](https://www.tapo.com/en/search/?q=H110) hub.
///
/// IR remotes are virtual child devices that are created by the Tapo app, either by
/// picking an appliance from TP-Link's IR database or by learning the keys from a
/// physical remote.
IrRemoteHandler(IrRemoteResult),
camel_case_device_info,
}
impl IrRemoteHandler {
/// Sends one of the IR keys stored on this remote.
///
/// # Arguments
///
/// * `key_name` - the [`name`](crate::tapo_vendor::responses::IrRemoteKey::name) of a key
/// from this remote's [`key_list`](crate::tapo_vendor::responses::IrRemoteResult::key_list)
///
/// # Example
///
/// ```ignore
/// # use tapo::{ApiClient, HubDevice};
/// # #[tokio::main]
/// # async fn main() -> Result<(), Box<dyn std::error::Error>> {
/// // Connect to the hub
/// let hub = ApiClient::new("tapo-username@example.com", "tapo-password")
/// .h110("192.168.1.100")
/// .await?;
/// // Get a handler for the IR remote
/// let remote = hub
/// .ir_remote(HubDevice::ByNickname("Living Room TV".to_string()))
/// .await?;
/// // Send one of the keys stored on the remote
/// remote.send_key_by_name("POWER").await?;
/// # Ok(())
/// # }
/// ```
pub async fn send_key_by_name(&self, key_name: impl Into<String>) -> Result<(), Error> {
let request =
TapoRequest::SendIrCmdById(TapoParams::new(SendIrCmdByIdParams::new(key_name)));
self.client
.read()
.await
.control_child::<serde_json::Value>(self.device_id.clone(), request)
.await?;
Ok(())
}
}