use erased_serde::Serialize;
use serde::de::DeserializeOwned;
use serde_json::Value as JsonValue;
use uuid::Uuid;
use crate::client::{DeviceBase, HlapiClient, HlapiClientError};
#[derive(Debug, Clone)]
pub struct GenericDevice {
client: HlapiClient,
uuid: Uuid,
}
impl GenericDevice {
#[allow(clippy::type_complexity)]
pub fn call<R: DeserializeOwned>(
&self,
method: &str,
args: &[&dyn Serialize],
blobs: &[&[u8]],
) -> Result<(R, Vec<Vec<u8>>), HlapiClientError> {
<Self as DeviceBase>::call(self, method, args, blobs)
}
}
impl DeviceBase for GenericDevice {
const TYPE: &'static str = "";
type Event = (String, JsonValue);
fn new(client: HlapiClient, uuid: Uuid) -> Result<Self, HlapiClientError> {
Ok(Self { client, uuid })
}
fn uuid_base(&self) -> Uuid {
self.uuid
}
fn client(&self) -> &HlapiClient {
&self.client
}
fn parse_event(
typ: &str,
data: &JsonValue,
) -> Result<Self::Event, Box<dyn std::error::Error + Send + Sync>> {
Ok((typ.to_owned(), data.clone()))
}
}