use {
crate::{client::TpLinkClient, error::Result},
serde_json::json,
};
impl TpLinkClient {
pub async fn turn_plug_on(&self, ip: &str) -> Result<()> {
self.send(ip, json!({"system":{"set_relay_state":{"state": 1}}}))
.await?;
Ok(())
}
pub async fn turn_plug_off(&self, ip: &str) -> Result<()> {
self.send(ip, json!({"system":{"set_relay_state":{"state": 0}}}))
.await?;
Ok(())
}
pub async fn set_plug_alias(&self, ip: &str, alias: &str) -> Result<()> {
self.send(ip, json!({"system":{"set_dev_alias":{"alias": alias}}}))
.await?;
Ok(())
}
pub async fn reboot_plug(&self, ip: &str) -> Result<()> {
self.send(ip, json!({"system":{"reboot":{"delay": 1}}}))
.await?;
Ok(())
}
}
pub async fn turn_plug_on(ip: &str) -> Result<()> {
TpLinkClient::new().turn_plug_on(ip).await
}
pub async fn turn_plug_off(ip: &str) -> Result<()> {
TpLinkClient::new().turn_plug_off(ip).await
}
pub async fn set_plug_alias(ip: &str, alias: &str) -> Result<()> {
TpLinkClient::new().set_plug_alias(ip, alias).await
}
pub async fn reboot_plug(ip: &str) -> Result<()> {
TpLinkClient::new().reboot_plug(ip).await
}