use serde_json::json;
use crate::error::Result;
use crate::types::AqaraValueResponse;
use crate::types::voice::CommandDeviceResourceParams;
#[cfg(feature = "async")]
use crate::Client;
#[cfg(feature = "blocking")]
use crate::BlockingClient;
#[cfg(feature = "async")]
#[derive(Clone)]
pub struct VoiceService {
client: Client,
}
#[cfg(feature = "async")]
impl VoiceService {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn command_device_resource(
&self,
params: CommandDeviceResourceParams,
) -> Result<AqaraValueResponse> {
let data = json!({
"positionId": params.position_id,
"queryText": params.query_text,
});
self.client
.call_json("command.device.resource", data, true, false)
.await
}
}
#[cfg(feature = "blocking")]
#[derive(Clone)]
pub struct BlockingVoiceService {
client: BlockingClient,
}
#[cfg(feature = "blocking")]
impl BlockingVoiceService {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn command_device_resource(
&self,
params: CommandDeviceResourceParams,
) -> Result<AqaraValueResponse> {
let data = json!({
"positionId": params.position_id,
"queryText": params.query_text,
});
self.client
.call_json("command.device.resource", data, true, false)
}
}