diff --git a/examples/chip-tool/commands/common/CommandInvoker.h b/examples/chip-tool/commands/common/CommandInvoker.h index 30613dfc54710f..3f7f12f276df80 100644 --- a/examples/chip-tool/commands/common/CommandInvoker.h +++ b/examples/chip-tool/commands/common/CommandInvoker.h @@ -86,7 +86,7 @@ class CommandInvoker final : public ResponseReceiver(this, aDevice->GetExchangeManager()); VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY); @@ -96,6 +96,38 @@ class CommandInvoker final : public ResponseReceiver(this, aDevice->GetExchangeManager()); + VerifyOrReturnError(commandSender != nullptr, CHIP_ERROR_NO_MEMORY); + + ReturnErrorOnFailure(commandSender->AddRequestData(commandPath, aRequestData)); + + if (aDevice->GetSecureSession().HasValue()) + { + SessionHandle session = aDevice->GetSecureSession().Value(); + session.SetGroupId(groupId); + + if (!session.IsGroupSession()) + { + return CHIP_ERROR_INCORRECT_STATE; + } + + ReturnErrorOnFailure(commandSender->SendCommandRequest(session)); + } + else + { + // something fishy is going on + return CHIP_ERROR_INCORRECT_STATE; + } + + commandSender.release(); + return CHIP_NO_ERROR; + } }; template @@ -162,5 +194,18 @@ CHIP_ERROR InvokeCommand(DeviceProxy * aDevice, void * aContext, return CHIP_NO_ERROR; } +template +CHIP_ERROR InvokeGroupCommand(DeviceProxy * aDevice, void * aContext, + typename detail::CommandInvoker::SuccessCallback aSuccessCallback, + typename detail::CommandInvoker::FailureCallback aFailureCallback, GroupId groupId, + const RequestType & aRequestData) +{ + auto invoker = detail::CommandInvoker::Alloc(aContext, aSuccessCallback, aFailureCallback); + VerifyOrReturnError(invoker != nullptr, CHIP_ERROR_NO_MEMORY); + ReturnErrorOnFailure(invoker->InvokeGroupCommand(aDevice, groupId, aRequestData)); + invoker.release(); + return CHIP_NO_ERROR; +} + } // namespace Controller } // namespace chip diff --git a/examples/chip-tool/templates/partials/test_cluster.zapt b/examples/chip-tool/templates/partials/test_cluster.zapt index 713cc0effd4442..9e637b51ea0a49 100644 --- a/examples/chip-tool/templates/partials/test_cluster.zapt +++ b/examples/chip-tool/templates/partials/test_cluster.zapt @@ -194,7 +194,7 @@ class {{filename}}: public TestCommand (static_cast<{{filename}} *>(context))->OnFailureResponse_{{index}}(status); }; - ReturnErrorOnFailure(chip::Controller::InvokeCommand(mDevice, this, success, failure, endpoint, request)); + ReturnErrorOnFailure(chip::Controller::{{#if isGroupCommand}}InvokeGroupCommand{{else}}InvokeCommand{{/if}}(mDevice, this, success, failure, {{#if isGroupCommand}}groupId{{else}}endpoint{{/if}}, request)); {{#unless async}}return CHIP_NO_ERROR;{{/unless}} {{else}} chip::Controller::{{asUpperCamelCase cluster}}ClusterTest cluster; diff --git a/src/app/tests/suites/TestGroupMessaging.yaml b/src/app/tests/suites/TestGroupMessaging.yaml index d80d32ebffc1ef..0483ed5a6a9af8 100644 --- a/src/app/tests/suites/TestGroupMessaging.yaml +++ b/src/app/tests/suites/TestGroupMessaging.yaml @@ -52,3 +52,17 @@ tests: attribute: "location" response: value: "" + + - label: "Turn On the light to see attribute change" + cluster: "On/Off" + command: "On" + groupId: "1234" + disabled: true + + - label: "Check on/off attribute value is true after on command" + cluster: "On/Off" + command: "readAttribute" + attribute: "OnOff" + disabled: true + response: + value: 1 diff --git a/src/app/zap-templates/common/ClusterTestGeneration.js b/src/app/zap-templates/common/ClusterTestGeneration.js index cce097787c912d..ee1e0f7f8c37af 100644 --- a/src/app/zap-templates/common/ClusterTestGeneration.js +++ b/src/app/zap-templates/common/ClusterTestGeneration.js @@ -139,6 +139,10 @@ function setDefaultTypeForCommand(test) default: test.commandName = test.command; test.isCommand = true; + if ((kGroupId in test)) { + test.isGroupCommand = true; + test.groupId = parseInt(test[kGroupId], 10); + } break; }