Skip to content

Commit

Permalink
Add RequestSelfTest public function
Browse files Browse the repository at this point in the history
  • Loading branch information
hare-siterwell authored and ericzijian1994 committed Aug 21, 2023
1 parent cb30cd2 commit 1265986
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 33 deletions.
50 changes: 25 additions & 25 deletions src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ void SmokeCoAlarmServer::SetExpressedStateByPriority(EndpointId endpointId,
SetExpressedState(endpointId, ExpressedStateEnum::kNormal);
}

bool SmokeCoAlarmServer::RequestSelfTest(EndpointId endpointId)
{
ExpressedStateEnum expressedState;
VerifyOrReturnValue(GetExpressedState(endpointId, expressedState), false);

// If the value is busy then return busy
if (expressedState == ExpressedStateEnum::kSmokeAlarm || expressedState == ExpressedStateEnum::kCOAlarm ||
expressedState == ExpressedStateEnum::kTesting || expressedState == ExpressedStateEnum::kInterconnectSmoke ||
expressedState == ExpressedStateEnum::kInterconnectCO)
{
return false;
}

VerifyOrReturnValue(SetTestInProgress(endpointId, true), false);
SetExpressedState(endpointId, ExpressedStateEnum::kTesting);

emberAfPluginSmokeCoAlarmSelfTestRequestCommand(endpointId);

return true;
}

bool SmokeCoAlarmServer::SetSmokeState(EndpointId endpointId, AlarmStateEnum newSmokeState)
{
AlarmStateEnum alarmState;
Expand Down Expand Up @@ -404,30 +425,6 @@ void SmokeCoAlarmServer::SetExpressedState(EndpointId endpointId, ExpressedState
}
}

void SmokeCoAlarmServer::HandleRemoteSelfTestRequest(CommandHandler * commandObj, const ConcreteCommandPath & commandPath)
{
EndpointId endpointId = commandPath.mEndpointId;

ExpressedStateEnum expressedState;
VerifyOrReturn(GetExpressedState(endpointId, expressedState), commandObj->AddStatus(commandPath, Status::Failure));

// If the value is busy then return busy
if (expressedState == ExpressedStateEnum::kSmokeAlarm || expressedState == ExpressedStateEnum::kCOAlarm ||
expressedState == ExpressedStateEnum::kTesting || expressedState == ExpressedStateEnum::kInterconnectSmoke ||
expressedState == ExpressedStateEnum::kInterconnectCO)
{
commandObj->AddStatus(commandPath, Status::Busy);
return;
}

VerifyOrReturn(SetTestInProgress(endpointId, true), commandObj->AddStatus(commandPath, Status::Failure));
SetExpressedState(endpointId, ExpressedStateEnum::kTesting);

emberAfPluginSmokeCoAlarmSelfTestRequestCommand(endpointId);

commandObj->AddStatus(commandPath, Status::Success);
}

template <typename T>
void SmokeCoAlarmServer::SendEvent(EndpointId endpointId, T & event)
{
Expand Down Expand Up @@ -478,7 +475,10 @@ bool SmokeCoAlarmServer::SetAttribute(EndpointId endpointId, AttributeId attribu
bool emberAfSmokeCoAlarmClusterSelfTestRequestCallback(CommandHandler * commandObj, const ConcreteCommandPath & commandPath,
const Commands::SelfTestRequest::DecodableType & commandData)
{
SmokeCoAlarmServer::Instance().HandleRemoteSelfTestRequest(commandObj, commandPath);
auto success = SmokeCoAlarmServer::Instance().RequestSelfTest(commandPath.mEndpointId);

commandObj->AddStatus(commandPath, success ? Status::Success : Status::Failure);

return true;
}

Expand Down
15 changes: 7 additions & 8 deletions src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ class SmokeCoAlarmServer
void SetExpressedStateByPriority(chip::EndpointId endpointId,
const std::array<ExpressedStateEnum, kPriorityOrderLength> & priorityOrder);

/**
* @brief Set the highest level of Expressed State according to priorityOrder
* @param endpointId ID of the endpoint
* @return true on success, false on failure
*/
bool RequestSelfTest(chip::EndpointId endpointId);

/**
* For all the functions below, the return value is true on success, false on failure
*/
Expand Down Expand Up @@ -101,14 +108,6 @@ class SmokeCoAlarmServer
*/
void SetExpressedState(chip::EndpointId endpointId, ExpressedStateEnum newExpressedState);

/**
* @brief Common handler for SelfTestRequest commands
*
* @param commandObj original command context
* @param commandPath original command path
*/
void HandleRemoteSelfTestRequest(chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath);

/**
* @brief Send generic event
*
Expand Down

0 comments on commit 1265986

Please sign in to comment.