From 126598675a77779f0be2cd4d1a6fc3869b847ccb Mon Sep 17 00:00:00 2001 From: Hare Date: Fri, 18 Aug 2023 16:30:02 +0800 Subject: [PATCH] Add RequestSelfTest public function --- .../smoke-co-alarm-server.cpp | 50 +++++++++---------- .../smoke-co-alarm-server.h | 15 +++--- 2 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.cpp b/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.cpp index 7b4236044a21f4..7783a21987ed1b 100644 --- a/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.cpp +++ b/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.cpp @@ -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; @@ -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 void SmokeCoAlarmServer::SendEvent(EndpointId endpointId, T & event) { @@ -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; } diff --git a/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h b/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h index 0abfe5cc7a5dba..fdf9fb4e147c55 100644 --- a/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h +++ b/src/app/clusters/smoke-co-alarm-server/smoke-co-alarm-server.h @@ -54,6 +54,13 @@ class SmokeCoAlarmServer void SetExpressedStateByPriority(chip::EndpointId endpointId, const std::array & 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 */ @@ -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 *