diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index 7c5b2c906ab69c..421284a0ae795b 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -145,18 +145,20 @@ class ReadClientCallback : public ReadClient::Callback void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override { + // Only enable auto resubscribe if the subscription is established successfully. + mAutoResubscribeNeeded = mAutoResubscribe; gOnSubscriptionEstablishedCallback(mAppContext, aSubscriptionId); } CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override { - if (mAutoResubscribe) + if (mAutoResubscribeNeeded) { ReturnErrorOnFailure(ReadClient::Callback::OnResubscriptionNeeded(apReadClient, aTerminationCause)); } gOnResubscriptionAttemptedCallback(mAppContext, ToPyChipError(aTerminationCause), apReadClient->ComputeTimeTillNextSubscription()); - if (mAutoResubscribe) + if (mAutoResubscribeNeeded) { return CHIP_NO_ERROR; } @@ -242,7 +244,8 @@ class ReadClientCallback : public ReadClient::Callback PyObject * mAppContext; std::unique_ptr mReadClient; - bool mAutoResubscribe = true; + bool mAutoResubscribe = true; + bool mAutoResubscribeNeeded = false; }; extern "C" {