use super::base::*;
use crate::alink::{global_id_next, AlinkRequest, AlinkResponse, SysAck, ALINK_VERSION};
use crate::Error;
use log::debug;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::fs;
impl super::Module {
pub async fn update(&self, infos: Vec<DeviceInfoKeyValue>, ack: bool) -> crate::Result<()> {
let payload = DeviceInfoUpdateRequest {
id: global_id_next().to_string(),
version: ALINK_VERSION.to_string(),
params: infos,
sys: Some(SysAck { ack: ack.into() }),
method: Some("thing.deviceinfo.update".to_string()),
};
self.publish(
format!(
"/sys/{}/{}/thing/deviceinfo/update",
self.three.product_key, self.three.device_name
),
&payload,
)
.await
}
pub async fn delete(&self, keys: &[&str], ack: bool) -> crate::Result<()> {
let payload = DeviceInfoDeleteRequest {
id: global_id_next().to_string(),
version: ALINK_VERSION.to_string(),
params: keys
.iter()
.map(|n| DeviceInfoKey {
attr_key: String::from(*n),
})
.collect(),
sys: Some(SysAck { ack: ack.into() }),
method: Some("thing.deviceinfo.delete".to_string()),
};
self.publish(
format!(
"/sys/{}/{}/thing/deviceinfo/delete",
self.three.product_key, self.three.device_name
),
&payload,
)
.await
}
}
pub type DeviceInfoUpdateRequest = AlinkRequest<Vec<DeviceInfoKeyValue>>;
pub type DeviceInfoDeleteRequest = AlinkRequest<Vec<DeviceInfoKey>>;