From dd99ce550bc06875dcbaa00afcc10d3d17cfc2fa Mon Sep 17 00:00:00 2001
From: Adrian Friedli <adrian.friedli@husqvarnagroup.com>
Date: Fri, 13 Sep 2024 19:01:45 +0200
Subject: [PATCH] allow endpoints with multiple device types

---
 examples/onoff_light/src/main.rs                    | 2 +-
 examples/onoff_light_bt/src/main.rs                 | 2 +-
 rs-matter/src/data_model/objects/endpoint.rs        | 2 +-
 rs-matter/src/data_model/root_endpoint.rs           | 2 +-
 rs-matter/src/data_model/system_model/descriptor.rs | 5 +++--
 rs-matter/tests/common/e2e/im/handler.rs            | 4 ++--
 rs-matter/tests/common/im_engine.rs                 | 4 ++--
 7 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/examples/onoff_light/src/main.rs b/examples/onoff_light/src/main.rs
index 3ba694b2..15fc3fee 100644
--- a/examples/onoff_light/src/main.rs
+++ b/examples/onoff_light/src/main.rs
@@ -195,7 +195,7 @@ const NODE: Node<'static> = Node {
         root_endpoint::endpoint(0, root_endpoint::OperNwType::Ethernet),
         Endpoint {
             id: 1,
-            device_type: DEV_TYPE_ON_OFF_LIGHT,
+            device_types: &[DEV_TYPE_ON_OFF_LIGHT],
             clusters: &[descriptor::CLUSTER, cluster_on_off::CLUSTER],
         },
     ],
diff --git a/examples/onoff_light_bt/src/main.rs b/examples/onoff_light_bt/src/main.rs
index 8099eb28..14cdf825 100644
--- a/examples/onoff_light_bt/src/main.rs
+++ b/examples/onoff_light_bt/src/main.rs
@@ -244,7 +244,7 @@ const NODE: Node<'static> = Node {
         root_endpoint::endpoint(0, root_endpoint::OperNwType::Wifi),
         Endpoint {
             id: 1,
-            device_type: DEV_TYPE_ON_OFF_LIGHT,
+            device_types: &[DEV_TYPE_ON_OFF_LIGHT],
             clusters: &[descriptor::CLUSTER, cluster_on_off::CLUSTER],
         },
     ],
diff --git a/rs-matter/src/data_model/objects/endpoint.rs b/rs-matter/src/data_model/objects/endpoint.rs
index 05878edc..c84583ed 100644
--- a/rs-matter/src/data_model/objects/endpoint.rs
+++ b/rs-matter/src/data_model/objects/endpoint.rs
@@ -24,7 +24,7 @@ use super::{AttrId, Attribute, Cluster, ClusterId, CmdId, DeviceType, EndptId};
 #[derive(Debug, Clone)]
 pub struct Endpoint<'a> {
     pub id: EndptId,
-    pub device_type: DeviceType,
+    pub device_types: &'a [DeviceType],
     pub clusters: &'a [Cluster<'a>],
 }
 
diff --git a/rs-matter/src/data_model/root_endpoint.rs b/rs-matter/src/data_model/root_endpoint.rs
index ce86a603..2ed71bac 100644
--- a/rs-matter/src/data_model/root_endpoint.rs
+++ b/rs-matter/src/data_model/root_endpoint.rs
@@ -52,7 +52,7 @@ pub enum OperNwType {
 pub const fn endpoint(id: EndptId, op_nw_type: OperNwType) -> Endpoint<'static> {
     Endpoint {
         id,
-        device_type: super::device_types::DEV_TYPE_ROOT_NODE,
+        device_types: &[super::device_types::DEV_TYPE_ROOT_NODE],
         clusters: clusters(op_nw_type),
     }
 }
diff --git a/rs-matter/src/data_model/system_model/descriptor.rs b/rs-matter/src/data_model/system_model/descriptor.rs
index a5501a8a..cbeca61e 100644
--- a/rs-matter/src/data_model/system_model/descriptor.rs
+++ b/rs-matter/src/data_model/system_model/descriptor.rs
@@ -182,8 +182,9 @@ impl<'a> DescriptorCluster<'a> {
         tw.start_array(tag)?;
         for endpoint in node.endpoints {
             if endpoint.id == endpoint_id {
-                let dev_type = endpoint.device_type;
-                dev_type.to_tlv(&TagType::Anonymous, &mut *tw)?;
+                for dev_type in endpoint.device_types {
+                    dev_type.to_tlv(&TagType::Anonymous, &mut *tw)?;
+                }
             }
         }
 
diff --git a/rs-matter/tests/common/e2e/im/handler.rs b/rs-matter/tests/common/e2e/im/handler.rs
index b8487a84..59049b60 100644
--- a/rs-matter/tests/common/e2e/im/handler.rs
+++ b/rs-matter/tests/common/e2e/im/handler.rs
@@ -60,7 +60,7 @@ impl<'a> E2eTestHandler<'a> {
                     access_control::CLUSTER,
                     echo_cluster::CLUSTER,
                 ],
-                device_type: DEV_TYPE_ROOT_NODE,
+                device_types: &[DEV_TYPE_ROOT_NODE],
             },
             Endpoint {
                 id: 1,
@@ -69,7 +69,7 @@ impl<'a> E2eTestHandler<'a> {
                     cluster_on_off::CLUSTER,
                     echo_cluster::CLUSTER,
                 ],
-                device_type: DEV_TYPE_ON_OFF_LIGHT,
+                device_types: &[DEV_TYPE_ON_OFF_LIGHT],
             },
         ],
     };
diff --git a/rs-matter/tests/common/im_engine.rs b/rs-matter/tests/common/im_engine.rs
index 50fd67ca..65532441 100644
--- a/rs-matter/tests/common/im_engine.rs
+++ b/rs-matter/tests/common/im_engine.rs
@@ -109,7 +109,7 @@ const NODE: Node<'static> = Node {
                 access_control::CLUSTER,
                 echo_cluster::CLUSTER,
             ],
-            device_type: DEV_TYPE_ROOT_NODE,
+            device_types: &[DEV_TYPE_ROOT_NODE],
         },
         Endpoint {
             id: 1,
@@ -118,7 +118,7 @@ const NODE: Node<'static> = Node {
                 cluster_on_off::CLUSTER,
                 echo_cluster::CLUSTER,
             ],
-            device_type: DEV_TYPE_ON_OFF_LIGHT,
+            device_types: &[DEV_TYPE_ON_OFF_LIGHT],
         },
     ],
 };