From 10911425414e234ab22368caf279682bad4a0e17 Mon Sep 17 00:00:00 2001 From: William Date: Thu, 10 Aug 2023 12:12:50 +0100 Subject: [PATCH] Check if Mode Base is already in the requested mode before calling the delegate. (#28610) --- .../mode-base-server/mode-base-server.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/app/clusters/mode-base-server/mode-base-server.cpp b/src/app/clusters/mode-base-server/mode-base-server.cpp index cb55bc214c8676..2b9cc232f87e8d 100644 --- a/src/app/clusters/mode-base-server/mode-base-server.cpp +++ b/src/app/clusters/mode-base-server/mode-base-server.cpp @@ -368,6 +368,11 @@ void Instance::HandleChangeToMode(HandlerContext & ctx, const Commands::ChangeTo Commands::ChangeToModeResponse::Type response; + // If the NewMode field doesn't match the Mode field of any entry of the SupportedModes list, + // the ChangeToModeResponse command's Status field SHALL indicate UnsupportedMode and + // the StatusText field SHALL be included and MAY be used to indicate the issue, with a human readable string, + // or include an empty string. + // We are leaving the StatusText empty since the Status is descriptive enough. if (!IsSupportedMode(newMode)) { ChipLogError(Zcl, "ModeBase: Failed to find the option with mode %u", newMode); @@ -376,6 +381,17 @@ void Instance::HandleChangeToMode(HandlerContext & ctx, const Commands::ChangeTo return; } + // If the NewMode field is the same as the value of the CurrentMode attribute + // the ChangeToModeResponse command SHALL have the Status field set to Success and + // the StatusText field MAY be supplied with a human readable string or include an empty string. + // We are leaving the StatusText empty since the Status is descriptive enough. + if (newMode == GetCurrentMode()) + { + response.status = to_underlying(ModeBase::StatusCode::kSuccess); + ctx.mCommandHandler.AddResponse(ctx.mRequestPath, response); + return; + } + mDelegate->HandleChangeToMode(newMode, response); if (response.status == to_underlying(StatusCode::kSuccess))