use serde_json::json;
use crate::error::Result;
use crate::types::AqaraValueResponse;
use crate::types::ota::{OtaFirmwareParams, OtaUpgradeParams, OtaUpgradeStatusParams};
#[cfg(feature = "async")]
use crate::Client;
#[cfg(feature = "blocking")]
use crate::BlockingClient;
#[cfg(feature = "async")]
#[derive(Clone)]
pub struct OtaService {
client: Client,
}
#[cfg(feature = "async")]
impl OtaService {
pub(crate) fn new(client: Client) -> Self {
Self { client }
}
pub async fn firmware(&self, params: OtaFirmwareParams) -> Result<AqaraValueResponse> {
let data = json!({ "model": params.model });
self.client
.call_json("query.ota.firmware", data, true, true)
.await
}
pub async fn upgrade(&self, params: OtaUpgradeParams) -> Result<AqaraValueResponse> {
let data = json!({ "dids": params.dids });
self.client
.call_json("write.ota.upgrade", data, true, false)
.await
}
pub async fn upgrade_status(
&self,
params: OtaUpgradeStatusParams,
) -> Result<AqaraValueResponse> {
let data = json!({ "dids": params.dids });
self.client
.call_json("query.ota.upgrade", data, true, true)
.await
}
}
#[cfg(feature = "blocking")]
#[derive(Clone)]
pub struct BlockingOtaService {
client: BlockingClient,
}
#[cfg(feature = "blocking")]
impl BlockingOtaService {
pub(crate) fn new(client: BlockingClient) -> Self {
Self { client }
}
pub fn firmware(&self, params: OtaFirmwareParams) -> Result<AqaraValueResponse> {
let data = json!({ "model": params.model });
self.client
.call_json("query.ota.firmware", data, true, true)
}
pub fn upgrade(&self, params: OtaUpgradeParams) -> Result<AqaraValueResponse> {
let data = json!({ "dids": params.dids });
self.client
.call_json("write.ota.upgrade", data, true, false)
}
pub fn upgrade_status(&self, params: OtaUpgradeStatusParams) -> Result<AqaraValueResponse> {
let data = json!({ "dids": params.dids });
self.client.call_json("query.ota.upgrade", data, true, true)
}
}