@@ -25,6 +25,7 @@ local mock_device = test.mock_device.build_test_matter_device({
2525 vendor_id = 0x0000 ,
2626 product_id = 0x0000 ,
2727 },
28+ matter_version = {hardware = 1 , software = 1 },
2829 endpoints = {
2930 {
3031 endpoint_id = 0 ,
@@ -105,6 +106,7 @@ local mock_device_mcd_unsupported_switch_device_type = test.mock_device.build_te
105106 vendor_id = 0x0000 ,
106107 product_id = 0x0000 ,
107108 },
109+ matter_version = {hardware = 1 , software = 1 },
108110 endpoints = {
109111 {
110112 endpoint_id = 0 ,
@@ -192,49 +194,35 @@ local function expect_configure_buttons()
192194 test .socket .capability :__expect_send (mock_device :generate_test_message (" button3" , button_attr .pushed ({state_change = false })))
193195end
194196
195- -- All messages queued and expectations set are done before the driver is actually run
196197local function test_init ()
197- -- we dont want the integration test framework to generate init/doConfigure, we are doing that here
198- -- so we can set the proper expectations on those events.
199198 test .disable_startup_messages ()
200199 test .mock_device .add_test_device (mock_device ) -- make sure the cache is populated
201200 test .mock_device .add_test_device (mock_child )
202201
203- -- added sets a bunch of fields on the device, and calls init
204202 local subscribe_request = CLUSTER_SUBSCRIBE_LIST [1 ]:subscribe (mock_device )
205203 for i , clus in ipairs (CLUSTER_SUBSCRIBE_LIST ) do
206204 if i > 1 then subscribe_request :merge (clus :subscribe (mock_device )) end
207205 end
208206 test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
209207 test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " added" })
210208
211- -- init results in subscription interaction
212209 test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
213210 test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " init" })
214211
215- -- doConfigure sets the provisioning state to provisioned
216- mock_device :expect_metadata_update ({ profile = " light-level-3-button" })
217- mock_device :expect_metadata_update ({ provisioning_state = " PROVISIONED" })
212+ test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " doConfigure" })
218213 mock_device :expect_device_create ({
219214 type = " EDGE_CHILD" ,
220215 label = " Matter Switch 2" ,
221216 profile = " light-color-level" ,
222217 parent_device_id = mock_device .id ,
223218 parent_assigned_child_key = string.format (" %d" , mock_device_ep5 )
224219 })
220+ mock_device :expect_metadata_update ({ profile = " light-level-3-button" })
225221 expect_configure_buttons ()
226- test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " doConfigure" })
227-
228- -- simulate the profile change update taking affect and the device info changing
229- local device_info_copy = utils .deep_copy (mock_device .raw_st_data )
230- device_info_copy .profile .id = " 5-buttons-battery"
231- local device_info_json = dkjson .encode (device_info_copy )
232- test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " infoChanged" , device_info_json })
233- test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
234- expect_configure_buttons ()
222+ mock_device :expect_metadata_update ({ provisioning_state = " PROVISIONED" })
235223
236- test .socket .matter :__expect_send ({mock_device .id , clusters .OnOff .attributes .OnOff :read (mock_device )})
237224 test .socket .device_lifecycle :__queue_receive ({ mock_child .id , " added" })
225+ test .socket .matter :__expect_send ({mock_device .id , clusters .OnOff .attributes .OnOff :read (mock_device )})
238226 test .socket .device_lifecycle :__queue_receive ({ mock_child .id , " init" })
239227 mock_child :expect_metadata_update ({ provisioning_state = " PROVISIONED" })
240228 test .socket .device_lifecycle :__queue_receive ({ mock_child .id , " doConfigure" })
@@ -452,18 +440,48 @@ test.register_coroutine_test(
452440test .register_coroutine_test (
453441 " Test driver switched event" ,
454442 function ()
443+ test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " init" })
444+ local subscribe_request = CLUSTER_SUBSCRIBE_LIST [1 ]:subscribe (mock_device )
445+ for i , clus in ipairs (CLUSTER_SUBSCRIBE_LIST ) do
446+ if i > 1 then subscribe_request :merge (clus :subscribe (mock_device )) end
447+ end
448+ test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
455449 test .socket .device_lifecycle :__queue_receive ({ mock_device .id , " driverSwitched" })
450+ mock_child :expect_metadata_update ({ profile = " light-color-level" })
456451 mock_device :expect_metadata_update ({ profile = " light-level-3-button" })
457452 expect_configure_buttons ()
458- mock_device :expect_device_create ({
459- type = " EDGE_CHILD" ,
460- label = " Matter Switch 2" ,
461- profile = " light-color-level" ,
462- parent_device_id = mock_device .id ,
463- parent_assigned_child_key = string.format (" %d" , mock_device_ep5 )
464- })
465453 end
466454)
467455
456+ test .register_coroutine_test (
457+ " Test info changed event with parent device profile update" ,
458+ function ()
459+ local subscribe_request = CLUSTER_SUBSCRIBE_LIST [1 ]:subscribe (mock_device )
460+ for i , clus in ipairs (CLUSTER_SUBSCRIBE_LIST ) do
461+ if i > 1 then subscribe_request :merge (clus :subscribe (mock_device )) end
462+ end
463+ local updated_device_profile = t_utils .get_profile_definition (" light-level-3-button.yml" )
464+ updated_device_profile .id = " updated device profile id"
465+ test .socket .device_lifecycle :__queue_receive (mock_device :generate_info_changed ({ profile = updated_device_profile }))
466+ test .socket .matter :__expect_send ({mock_device .id , subscribe_request })
467+ expect_configure_buttons ()
468+ end
469+ )
470+
471+ test .register_coroutine_test (
472+ " Test info changed event with matter_version update" ,
473+ function ()
474+ local subscribe_request = CLUSTER_SUBSCRIBE_LIST [1 ]:subscribe (mock_device )
475+ for i , clus in ipairs (CLUSTER_SUBSCRIBE_LIST ) do
476+ if i > 1 then subscribe_request :merge (clus :subscribe (mock_device )) end
477+ end
478+ test .socket .device_lifecycle :__queue_receive (mock_device :generate_info_changed ({ matter_version = { hardware = 1 , software = 2 } })) -- bump to 2
479+ mock_child :expect_metadata_update ({ profile = " light-color-level" })
480+ mock_device :expect_metadata_update ({ profile = " light-level-3-button" })
481+ expect_configure_buttons ()
482+ end
483+ )
484+
485+
468486-- run the tests
469487test .run_registered_tests ()
0 commit comments