Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if Mode Base is already in the requested mode #28610

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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