15
15
# limitations under the License.
16
16
#
17
17
18
-
18
+ import asyncio
19
19
import base64
20
20
import copy
21
21
import json
@@ -98,12 +98,15 @@ def ConvertValue(value) -> Any:
98
98
99
99
100
100
class BasicCompositionTests :
101
- async def connect_over_pase (self , dev_ctrl ):
102
- asserts .assert_true (self .matter_test_config .qr_code_content == [] or self .matter_test_config .manual_code == [],
103
- "Cannot have both QR and manual code specified" )
104
- setupCode = self .matter_test_config .qr_code_content + self .matter_test_config .manual_code
105
- asserts .assert_equal (len (setupCode ), 1 , "Require one of either --qr-code or --manual-code." )
106
- await dev_ctrl .FindOrEstablishPASESession (setupCode [0 ], self .dut_node_id )
101
+ def get_code (self , dev_ctrl ):
102
+ created_codes = []
103
+ for idx , d in enumerate (self .matter_test_config .discriminators ):
104
+ created_codes .append (dev_ctrl .CreateManualCode (d , self .matter_test_config .setup_passcodes [idx ]))
105
+
106
+ setup_codes = self .matter_test_config .qr_code_content + self .matter_test_config .manual_code + created_codes
107
+ asserts .assert_equal (len (setup_codes ), 1 ,
108
+ "Require exactly one of either --qr-code, --manual-code or (--discriminator and --passcode)." )
109
+ return setup_codes [0 ]
107
110
108
111
def dump_wildcard (self , dump_device_composition_path : typing .Optional [str ]):
109
112
node_dump_dict = {endpoint_id : MatterTlvToJson (self .endpoints_tlv [endpoint_id ]) for endpoint_id in self .endpoints_tlv }
@@ -115,19 +118,34 @@ def dump_wildcard(self, dump_device_composition_path: typing.Optional[str]):
115
118
with open (pathlib .Path (dump_device_composition_path ).with_suffix (".txt" ), "wt+" ) as outfile :
116
119
pprint (self .endpoints , outfile , indent = 1 , width = 200 , compact = True )
117
120
118
- async def setup_class_helper (self , default_to_pase : bool = True ):
121
+ async def setup_class_helper (self , allow_pase : bool = True ):
119
122
dev_ctrl = self .default_controller
120
123
self .problems = []
121
124
122
- do_test_over_pase = self .user_params .get ("use_pase_only" , default_to_pase )
123
125
dump_device_composition_path : Optional [str ] = self .user_params .get ("dump_device_composition_path" , None )
124
126
125
- if do_test_over_pase :
126
- await self .connect_over_pase (dev_ctrl )
127
- node_id = self .dut_node_id
128
- else :
129
- # Using the already commissioned node
130
- node_id = self .dut_node_id
127
+ node_id = self .dut_node_id
128
+
129
+ task_list = []
130
+ if allow_pase :
131
+ setup_code = self .get_code (dev_ctrl )
132
+ pase_future = dev_ctrl .EstablishPASESession (setup_code , self .dut_node_id )
133
+ task_list .append (asyncio .create_task (pase_future ))
134
+
135
+ case_future = dev_ctrl .GetConnectedDevice (nodeid = node_id , allowPASE = False )
136
+ task_list .append (asyncio .create_task (case_future ))
137
+
138
+ for task in task_list :
139
+ asyncio .ensure_future (task )
140
+
141
+ done , pending = await asyncio .wait (task_list , return_when = asyncio .FIRST_COMPLETED )
142
+
143
+ for task in pending :
144
+ try :
145
+ task .cancel ()
146
+ await task
147
+ except asyncio .CancelledError :
148
+ pass
131
149
132
150
wildcard_read = (await dev_ctrl .Read (node_id , [()]))
133
151
0 commit comments