diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp index 6eda399dcde4f8..81f52d3b9e85d6 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp +++ b/src/app/clusters/ota-requestor/DefaultOTARequestor.cpp @@ -648,9 +648,6 @@ IdleStateReason DefaultOTARequestor::MapErrorToIdleStateReason(CHIP_ERROR error) void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAChangeReasonEnum reason, CHIP_ERROR error) { - bool handleIdleStateEnter = true; - IdleStateReason idleStateReason = IdleStateReason::kUnknown; - // Set server UpdateState attribute OtaRequestorServerSetUpdateState(newState); @@ -673,24 +670,20 @@ void DefaultOTARequestor::RecordNewUpdateState(OTAUpdateStateEnum newState, OTAC if ((newState == OTAUpdateStateEnum::kIdle) && (mCurrentUpdateState != OTAUpdateStateEnum::kIdle)) { - idleStateReason = MapErrorToIdleStateReason(error); - handleIdleStateEnter = true; + IdleStateReason idleStateReason = MapErrorToIdleStateReason(error); + // Update the new state before handling the state transition + mCurrentUpdateState = newState; + mOtaRequestorDriver->HandleIdleStateEnter(idleStateReason); } else if ((mCurrentUpdateState == OTAUpdateStateEnum::kIdle) && (newState != OTAUpdateStateEnum::kIdle)) { - handleIdleStateEnter = false; - } - - // Update the new state before handling the state transition - mCurrentUpdateState = newState; - - if (handleIdleStateEnter) - { - mOtaRequestorDriver->HandleIdleStateEnter(idleStateReason); + // Update the new state before handling the state transition + mCurrentUpdateState = newState; + mOtaRequestorDriver->HandleIdleStateExit(); } else { - mOtaRequestorDriver->HandleIdleStateExit(); + mCurrentUpdateState = newState; } } diff --git a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h index 0b9a93ec485d67..be3cfcf9604965 100644 --- a/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h +++ b/src/app/clusters/ota-requestor/DefaultOTARequestorDriver.h @@ -110,9 +110,9 @@ class DefaultOTARequestorDriver : public OTARequestorDriver // Maximum number of times to retry a BUSY OTA provider before moving to the next available one static constexpr uint8_t kMaxBusyProviderRetryCount = 3; // Track retry count for the current provider - uint8_t mProviderRetryCount; + uint8_t mProviderRetryCount = 0; // Track query image retry count on invalid session error - uint8_t mInvalidSessionRetryCount; + uint8_t mInvalidSessionRetryCount = 0; }; } // namespace DeviceLayer