Skip to content

Commit

Permalink
Check if Mode Base is already in the requested mode before calling th…
Browse files Browse the repository at this point in the history
…e delegate. (#28610)
  • Loading branch information
hicklin authored and pull[bot] committed Jan 22, 2024
1 parent 650a7d3 commit 1449912
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/app/clusters/mode-base-server/mode-base-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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))
Expand Down

0 comments on commit 1449912

Please sign in to comment.