|
1 |
| --- Copyright 2024 SmartThings |
| 1 | +-- Copyright 2025 SmartThings |
2 | 2 | --
|
3 | 3 | -- Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | -- you may not use this file except in compliance with the License.
|
|
15 | 15 | local test = require "integration_test"
|
16 | 16 | local capabilities = require "st.capabilities"
|
17 | 17 | local t_utils = require "integration_test.utils"
|
18 |
| - |
19 | 18 | local clusters = require "st.matter.clusters"
|
20 |
| - |
21 |
| -clusters.ElectricalEnergyMeasurement = require "ElectricalEnergyMeasurement" |
22 |
| -clusters.ElectricalPowerMeasurement = require "ElectricalPowerMeasurement" |
| 19 | +local version = require "version" |
| 20 | +if version.api < 11 then |
| 21 | + clusters.ElectricalEnergyMeasurement = require "ElectricalEnergyMeasurement" |
| 22 | + clusters.ElectricalPowerMeasurement = require "ElectricalPowerMeasurement" |
| 23 | +end |
23 | 24 |
|
24 | 25 | local mock_device = test.mock_device.build_test_matter_device({
|
25 | 26 | profile = t_utils.get_profile_definition("plug-level-power-energy-powerConsumption.yml"),
|
@@ -183,64 +184,54 @@ test.register_coroutine_test(
|
183 | 184 | end
|
184 | 185 | )
|
185 | 186 |
|
186 |
| -test.register_message_test( |
187 |
| - "On command should send the appropriate commands", |
188 |
| - { |
189 |
| - channel = "devices", |
190 |
| - direction = "send", |
191 |
| - message = { |
192 |
| - "register_native_capability_cmd_handler", |
193 |
| - { device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "on" } |
194 |
| - } |
195 |
| - }, |
196 |
| - { |
197 |
| - { |
198 |
| - channel = "capability", |
199 |
| - direction = "receive", |
200 |
| - message = { |
201 |
| - mock_device.id, |
202 |
| - { capability = "switch", component = "main", command = "on", args = { } } |
203 |
| - } |
204 |
| - }, |
205 |
| - { |
206 |
| - channel = "matter", |
207 |
| - direction = "send", |
208 |
| - message = { |
209 |
| - mock_device.id, |
210 |
| - clusters.OnOff.server.commands.On(mock_device, 2) |
211 |
| - } |
212 |
| - } |
213 |
| - } |
| 187 | +test.register_coroutine_test( |
| 188 | + "On command should send the appropriate commands", function() |
| 189 | + test.socket.capability:__queue_receive( |
| 190 | + { |
| 191 | + mock_device.id, |
| 192 | + { capability = "switch", component = "main", command = "on", args = { } } |
| 193 | + } |
| 194 | + ) |
| 195 | + if version.api >= 11 then |
| 196 | + test.socket.devices:__expect_send( |
| 197 | + { |
| 198 | + "register_native_capability_cmd_handler", |
| 199 | + { device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "on" } |
| 200 | + } |
| 201 | + ) |
| 202 | + end |
| 203 | + test.socket.matter:__expect_send( |
| 204 | + { |
| 205 | + mock_device.id, |
| 206 | + clusters.OnOff.server.commands.On(mock_device, 2) |
| 207 | + } |
| 208 | + ) |
| 209 | + end |
214 | 210 | )
|
215 | 211 |
|
216 |
| -test.register_message_test( |
217 |
| - "Off command should send the appropriate commands", |
218 |
| - { |
219 |
| - channel = "devices", |
220 |
| - direction = "send", |
221 |
| - message = { |
222 |
| - "register_native_capability_cmd_handler", |
223 |
| - { device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "off" } |
224 |
| - } |
225 |
| - }, |
226 |
| - { |
227 |
| - { |
228 |
| - channel = "capability", |
229 |
| - direction = "receive", |
230 |
| - message = { |
| 212 | +test.register_coroutine_test( |
| 213 | + "Off command should send the appropriate commands", function() |
| 214 | + test.socket.capability:__queue_receive( |
| 215 | + { |
231 | 216 | mock_device.id,
|
232 | 217 | { capability = "switch", component = "main", command = "off", args = { } }
|
233 | 218 | }
|
234 |
| - }, |
235 |
| - { |
236 |
| - channel = "matter", |
237 |
| - direction = "send", |
238 |
| - message = { |
| 219 | + ) |
| 220 | + if version.api >= 11 then |
| 221 | + test.socket.devices:__expect_send( |
| 222 | + { |
| 223 | + "register_native_capability_cmd_handler", |
| 224 | + { device_uuid = mock_device.id, capability_id = "switch", capability_cmd_id = "off" } |
| 225 | + } |
| 226 | + ) |
| 227 | + end |
| 228 | + test.socket.matter:__expect_send( |
| 229 | + { |
239 | 230 | mock_device.id,
|
240 | 231 | clusters.OnOff.server.commands.Off(mock_device, 2)
|
241 | 232 | }
|
242 |
| - } |
243 |
| - } |
| 233 | + ) |
| 234 | + end |
244 | 235 | )
|
245 | 236 |
|
246 | 237 | test.register_message_test(
|
@@ -681,68 +672,57 @@ test.register_coroutine_test(
|
681 | 672 | { test_init = test_init_periodic }
|
682 | 673 | )
|
683 | 674 |
|
684 |
| -test.register_message_test( |
685 |
| - "Set level command should send the appropriate commands", |
686 |
| - { |
687 |
| - { |
688 |
| - channel = "capability", |
689 |
| - direction = "receive", |
690 |
| - message = { |
| 675 | +test.register_coroutine_test( |
| 676 | + "Set level command should send the appropriate commands", function() |
| 677 | + test.socket.capability:__queue_receive( |
| 678 | + { |
691 | 679 | mock_device.id,
|
692 | 680 | { capability = "switchLevel", component = "main", command = "setLevel", args = {20,20} }
|
693 | 681 | }
|
694 |
| - }, |
695 |
| - { |
696 |
| - channel = "devices", |
697 |
| - direction = "send", |
698 |
| - message = { |
699 |
| - "register_native_capability_cmd_handler", |
700 |
| - { device_uuid = mock_device.id, capability_id = "switchLevel", capability_cmd_id = "setLevel" } |
701 |
| - } |
702 |
| - }, |
703 |
| - { |
704 |
| - channel = "matter", |
705 |
| - direction = "send", |
706 |
| - message = { |
| 682 | + ) |
| 683 | + if version.api >= 11 then |
| 684 | + test.socket.devices:__expect_send( |
| 685 | + { |
| 686 | + "register_native_capability_cmd_handler", |
| 687 | + { device_uuid = mock_device.id, capability_id = "switchLevel", capability_cmd_id = "setLevel" } |
| 688 | + } |
| 689 | + ) |
| 690 | + end |
| 691 | + test.socket.matter:__expect_send( |
| 692 | + { |
707 | 693 | mock_device.id,
|
708 | 694 | clusters.LevelControl.server.commands.MoveToLevelWithOnOff(mock_device, 2, math.floor(20/100.0 * 254), 20, 0 ,0)
|
709 | 695 | }
|
710 |
| - }, |
711 |
| - { |
712 |
| - channel = "matter", |
713 |
| - direction = "receive", |
714 |
| - message = { |
| 696 | + ) |
| 697 | + test.socket.matter:__queue_receive( |
| 698 | + { |
715 | 699 | mock_device.id,
|
716 | 700 | clusters.LevelControl.server.commands.MoveToLevelWithOnOff:build_test_command_response(mock_device, 2)
|
717 | 701 | }
|
718 |
| - }, |
719 |
| - { |
720 |
| - channel = "matter", |
721 |
| - direction = "receive", |
722 |
| - message = { |
| 702 | + ) |
| 703 | + test.socket.matter:__queue_receive( |
| 704 | + { |
723 | 705 | mock_device.id,
|
724 | 706 | clusters.LevelControl.attributes.CurrentLevel:build_test_report_data(mock_device, 2, 50)
|
725 | 707 | }
|
726 |
| - }, |
727 |
| - { |
728 |
| - channel = "capability", |
729 |
| - direction = "send", |
730 |
| - message = mock_device:generate_test_message("main", capabilities.switchLevel.level(20)) |
731 |
| - }, |
732 |
| - { |
733 |
| - channel = "matter", |
734 |
| - direction = "receive", |
735 |
| - message = { |
| 708 | + ) |
| 709 | + test.socket.capability:__expect_send( |
| 710 | + mock_device:generate_test_message( |
| 711 | + "main", capabilities.switchLevel.level(20) |
| 712 | + ) |
| 713 | + ) |
| 714 | + test.socket.matter:__queue_receive( |
| 715 | + { |
736 | 716 | mock_device.id,
|
737 | 717 | clusters.OnOff.attributes.OnOff:build_test_report_data(mock_device, 2, true)
|
738 | 718 | }
|
739 |
| - }, |
740 |
| - { |
741 |
| - channel = "capability", |
742 |
| - direction = "send", |
743 |
| - message = mock_device:generate_test_message("main", capabilities.switch.switch.on()) |
744 |
| - } |
745 |
| - } |
| 719 | + ) |
| 720 | + test.socket.capability:__expect_send( |
| 721 | + mock_device:generate_test_message( |
| 722 | + "main", capabilities.switch.switch.on() |
| 723 | + ) |
| 724 | + ) |
| 725 | + end |
746 | 726 | )
|
747 | 727 |
|
748 | 728 | test.run_registered_tests()
|
0 commit comments