Skip to content

Commit f104782

Browse files
authored
Add ability to process WaitForCommissionee YAML test command with chip-repl runner (#24332)
* Add ability to process WaitForCommissionee YAML test command * Address PR comments * Address PR comments
1 parent ff8fe37 commit f104782

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/controller/python/chip/yaml/runner.py

+46-1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,40 @@ def parse_raw_response(self, raw_resp) -> _ActionResult:
211211
return _ActionResult(status=_ActionStatus.SUCCESS, response=return_val)
212212

213213

214+
class WaitForCommissioneeAction(BaseAction):
215+
''' Wait for commissionee action to be executed.'''
216+
217+
def __init__(self, test_step):
218+
super().__init__(test_step.label)
219+
self._node_id = test_step.node_id
220+
self._expire_existing_session = False
221+
# This is the default when no timeout is provided.
222+
_DEFAULT_TIMEOUT_MS = 10 * 1000
223+
self._timeout_ms = _DEFAULT_TIMEOUT_MS
224+
225+
if test_step.arguments is None:
226+
# Nothing left for us to do the default values are what we want
227+
return
228+
229+
args = test_step.arguments['values']
230+
request_data_as_dict = Converter.convert_list_of_name_value_pair_to_dict(args)
231+
232+
self._expire_existing_session = request_data_as_dict.get('expireExistingSession', False)
233+
if 'timeout' in request_data_as_dict:
234+
# Timeout is provided in seconds we need to conver to milliseconds.
235+
self._timeout_ms = request_data_as_dict['timeout'] * 1000
236+
237+
def run_action(self, dev_ctrl: ChipDeviceCtrl) -> _ActionResult:
238+
try:
239+
if self._expire_existing_session:
240+
dev_ctrl.ExpireSessions(self._node_id)
241+
dev_ctrl.GetConnectedDeviceSync(self._node_id, timeoutMs=self._timeout_ms)
242+
except TimeoutError:
243+
return _ActionResult(status=_ActionStatus.ERROR, response=None)
244+
245+
return _ActionResult(status=_ActionStatus.SUCCESS, response=None)
246+
247+
214248
class AttributeChangeAccumulator:
215249
def __init__(self, name: str, expected_attribute: Clusters.ClusterAttributeDescriptor,
216250
output_queue: queue.SimpleQueue):
@@ -461,6 +495,15 @@ def _attribute_write_action_factory(self, test_step, cluster: str):
461495
except ParsingError:
462496
return None
463497

498+
def _wait_for_commissionee_action_factory(self, test_step):
499+
try:
500+
return WaitForCommissioneeAction(test_step)
501+
except ParsingError:
502+
# TODO For now, ParsingErrors are largely issues that will be addressed soon. Once this
503+
# runner has matched parity of the codegen YAML test, this exception should be
504+
# propogated.
505+
return None
506+
464507
def _wait_for_report_action_factory(self, test_step):
465508
try:
466509
return WaitForReportAction(test_step, self._context)
@@ -476,7 +519,9 @@ def encode(self, request) -> BaseAction:
476519
command = request.command
477520
# Some of the tests contain 'cluster over-rides' that refer to a different
478521
# cluster than that specified in 'config'.
479-
if command == 'writeAttribute':
522+
if cluster == 'DelayCommands' and command == 'WaitForCommissionee':
523+
action = self._wait_for_commissionee_action_factory(request)
524+
elif command == 'writeAttribute':
480525
action = self._attribute_write_action_factory(request, cluster)
481526
elif command == 'readAttribute':
482527
action = self._attribute_read_action_factory(request, cluster)

0 commit comments

Comments
 (0)