@@ -65,6 +65,44 @@ local mock_device = test.mock_device.build_test_matter_device({
6565 }
6666})
6767
68+ local mock_device_switch = test .mock_device .build_test_matter_device ({
69+ label = " Matter Switch" ,
70+ profile = t_utils .get_profile_definition (" switch-fan.yml" ),
71+ manufacturer_info = {
72+ vendor_id = 0x0000 ,
73+ product_id = 0x0000 ,
74+ },
75+ endpoints = {
76+ {
77+ endpoint_id = 0 ,
78+ clusters = {
79+ {cluster_id = clusters .Basic .ID , cluster_type = " SERVER" },
80+ },
81+ device_types = {
82+ {device_type_id = 0x0016 , device_type_revision = 1 } -- RootNode
83+ }
84+ },
85+ {
86+ endpoint_id = mock_device_ep1 ,
87+ clusters = {
88+ {cluster_id = clusters .OnOff .ID , cluster_type = " SERVER" },
89+ },
90+ device_types = {
91+ {device_type_id = 0x010A , device_type_revision = 2 } -- On Off Plugin Unit
92+ }
93+ },
94+ {
95+ endpoint_id = mock_device_ep2 ,
96+ clusters = {
97+ {cluster_id = clusters .FanControl .ID , cluster_type = " SERVER" , feature_map = 15 },
98+ },
99+ device_types = {
100+ {device_type_id = 0x002B , device_type_revision = 1 ,} -- Fan
101+ }
102+ }
103+ }
104+ })
105+
68106local CLUSTER_SUBSCRIBE_LIST = {
69107 clusters .OnOff .attributes .OnOff ,
70108 clusters .LevelControl .attributes .CurrentLevel ,
@@ -83,6 +121,13 @@ local CLUSTER_SUBSCRIBE_LIST ={
83121 clusters .FanControl .attributes .PercentCurrent ,
84122}
85123
124+ local SWITCH_CLUSTER_SUBSCRIBE_LIST = {
125+ clusters .OnOff .attributes .OnOff ,
126+ clusters .FanControl .attributes .FanModeSequence ,
127+ clusters .FanControl .attributes .FanMode ,
128+ clusters .FanControl .attributes .PercentCurrent ,
129+ }
130+
86131local function test_init ()
87132 test .disable_startup_messages ()
88133 test .mock_device .add_test_device (mock_device )
104149
105150test .set_test_init_function (test_init )
106151
152+ local function test_init_switch ()
153+ test .disable_startup_messages ()
154+ test .mock_device .add_test_device (mock_device_switch )
155+ local subscribe_request = SWITCH_CLUSTER_SUBSCRIBE_LIST [1 ]:subscribe (mock_device_switch )
156+ for i , clus in ipairs (SWITCH_CLUSTER_SUBSCRIBE_LIST ) do
157+ if i > 1 then subscribe_request :merge (clus :subscribe (mock_device_switch )) end
158+ end
159+
160+ test .socket .device_lifecycle :__queue_receive ({ mock_device_switch .id , " added" })
161+ test .socket .matter :__expect_send ({mock_device_switch .id , subscribe_request })
162+
163+ test .socket .device_lifecycle :__queue_receive ({ mock_device_switch .id , " init" })
164+ test .socket .matter :__expect_send ({mock_device_switch .id , subscribe_request })
165+
166+ test .socket .device_lifecycle :__queue_receive ({ mock_device_switch .id , " doConfigure" })
167+ mock_device_switch :expect_metadata_update ({ profile = " switch-fan" })
168+ mock_device_switch :expect_metadata_update ({ provisioning_state = " PROVISIONED" })
169+ end
170+
171+ test .register_message_test (
172+ " On Off Plug In Unit + Fan should profile as switch-fan" ,
173+ {},
174+ { test_init = test_init_switch }
175+ )
176+
107177test .register_coroutine_test (
108178 " Switch capability should send the appropriate commands" , function ()
109179 test .socket .capability :__queue_receive (
0 commit comments