#![allow(deprecated)]
use serde_json::{Value, json};
use super::VtaClient;
use crate::error::VtaError;
use crate::trust_tasks;
const DEVICE_TT_TIMEOUT: u64 = 30;
impl VtaClient {
pub async fn device_register(
&self,
consumer_kind: Value,
display_name: &str,
platform: Option<&str>,
hpke_public_key: Option<&str>,
) -> Result<Value, VtaError> {
let mut payload = json!({
"consumerKind": consumer_kind,
"displayName": display_name,
});
if let Some(p) = platform {
payload["platform"] = json!(p);
}
if let Some(k) = hpke_public_key {
payload["hpkePublicKey"] = json!(k);
}
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_REGISTER_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_heartbeat(&self, platform: Option<&str>) -> Result<Value, VtaError> {
let mut payload = json!({});
if let Some(p) = platform {
payload["platform"] = json!(p);
}
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_HEARTBEAT_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_list(&self, filters: Value) -> Result<Value, VtaError> {
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_LIST_0_1,
filters,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_disable(&self, device_id: &str) -> Result<Value, VtaError> {
let payload = json!({ "deviceId": device_id });
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_DISABLE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_wipe(
&self,
device_id: &str,
reason: &str,
scope: &str,
) -> Result<Value, VtaError> {
let payload = json!({ "deviceId": device_id, "reason": reason, "scope": scope });
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_WIPE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
pub async fn device_set_wake(
&self,
gateway: &str,
handle: &str,
suggested_triggers: Vec<String>,
) -> Result<Value, VtaError> {
let payload = json!({
"wakeHandle": { "gateway": gateway, "handle": handle },
"suggestedTriggers": suggested_triggers,
});
self.dispatch_trust_task(
trust_tasks::TASK_DEVICE_SET_WAKE_0_1,
payload,
DEVICE_TT_TIMEOUT,
)
.await
}
}