use core::fmt;
use super::{Cluster, ClusterId, DeviceType, EndptId};
#[derive(Debug, Clone)]
#[cfg_attr(feature = "defmt", derive(defmt::Format))]
pub struct Endpoint<'a> {
pub id: EndptId,
pub device_types: &'a [DeviceType],
pub clusters: &'a [Cluster<'a>],
pub client_clusters: &'a [ClusterId],
}
impl<'a> Endpoint<'a> {
pub const fn new(
id: EndptId,
device_types: &'a [DeviceType],
clusters: &'a [Cluster<'a>],
) -> Self {
Self {
id,
device_types,
clusters,
client_clusters: &[],
}
}
pub const fn new_with_clients(
id: EndptId,
device_types: &'a [DeviceType],
clusters: &'a [Cluster<'a>],
client_clusters: &'a [ClusterId],
) -> Self {
Self {
id,
device_types,
clusters,
client_clusters,
}
}
pub fn cluster(&self, id: ClusterId) -> Option<&Cluster<'a>> {
self.clusters.iter().find(|cluster| cluster.id == id)
}
}
impl core::fmt::Display for Endpoint<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "clusters:[")?;
let mut comma = "";
for cluster in self.clusters {
write!(f, "{} {{ {} }}", comma, cluster)?;
comma = ", ";
}
write!(f, "]")
}
}