use crate::error::IotResult;
use crate::path::PropertyPath;
use crate::value::Value;
#[derive(Debug, Clone, PartialEq)]
pub struct PropertySample {
pub path: PropertyPath,
pub value: Value,
pub source_ts_ms: Option<i64>,
pub quality: u32,
}
impl PropertySample {
pub fn now(path: PropertyPath, value: Value) -> Self {
Self {
path,
value,
source_ts_ms: None,
quality: 0,
}
}
}
pub trait IotClient {
fn connect(&mut self) -> impl core::future::Future<Output = IotResult<()>> + Send;
fn disconnect(&mut self) -> impl core::future::Future<Output = IotResult<()>> + Send;
fn read_property(
&mut self,
path: &PropertyPath,
) -> impl core::future::Future<Output = IotResult<PropertySample>> + Send;
fn write_property(
&mut self,
path: &PropertyPath,
value: Value,
) -> impl core::future::Future<Output = IotResult<()>> + Send;
}
#[cfg(test)]
mod tests {
use super::*;
use crate::error::IotError;
use crate::path::PropertyPath;
use crate::thing::{FeatureId, PropertyId, ThingId};
struct Dummy;
impl IotClient for Dummy {
async fn connect(&mut self) -> IotResult<()> {
Ok(())
}
async fn disconnect(&mut self) -> IotResult<()> {
Ok(())
}
async fn read_property(&mut self, _p: &PropertyPath) -> IotResult<PropertySample> {
Err(IotError::NotConnected)
}
async fn write_property(&mut self, _p: &PropertyPath, _v: Value) -> IotResult<()> {
Err(IotError::NotConnected)
}
}
#[test]
fn afit_shape_compiles() {
let _ = Dummy;
let _path = PropertyPath::new(
ThingId::new("acme:x"),
FeatureId::new("f"),
PropertyId::new("p"),
);
}
}