diff --git a/src/app/BufferedReadCallback.h b/src/app/BufferedReadCallback.h index b24257884e1a77..5dc158fbbd6f3b 100644 --- a/src/app/BufferedReadCallback.h +++ b/src/app/BufferedReadCallback.h @@ -70,6 +70,10 @@ class BufferedReadCallback : public ReadClient::Callback // void OnReportBegin() override; void OnReportEnd() override; + void NotifySubscriptionStillActive(const ReadClient & apReadClient) override + { + mCallback.NotifySubscriptionStillActive(apReadClient); + } void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override; void OnError(CHIP_ERROR aError) override { diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index 9e46eed469d39f..3cb7eb3311095c 100644 --- a/src/controller/python/chip/clusters/Attribute.py +++ b/src/controller/python/chip/clusters/Attribute.py @@ -680,12 +680,52 @@ def __init__(self, future: Future, eventLoop, devCtrl, returnClusterObject: bool self._pReadClient = None self._pReadCallback = None self._resultError = None + + print("\n\n\n") + print(f"AsyncReadTransaction - __init__") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") def SetClientObjPointers(self, pReadClient, pReadCallback): self._pReadClient = pReadClient self._pReadCallback = pReadCallback + print("\n\n\n") + print(f"AsyncReadTransaction - SetClientObjPointers") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") def GetAllEventValues(self): + print("\n\n\n") + print(f"AsyncReadTransaction - GetAllEventValues") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") return self._events def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int, status: int, data: bytes): @@ -702,6 +742,20 @@ def handleAttributeData(self, path: AttributePathWithListIndex, dataVersion: int self._cache.UpdateTLV(path, dataVersion, attributeValue) self._changedPathSet.add(path) + print("\n\n\n") + print(f"AsyncReadTransaction - handleAttributeData") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") + except Exception as ex: logging.exception(ex) @@ -742,11 +796,39 @@ def handleEventData(self, header: EventHeader, path: EventPath, data: bytes, sta self._subscription_handler.OnEventChangeCb( eventResult, self._subscription_handler) + print("\n\n\n") + print(f"AsyncReadTransaction - handleEventData") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") + except Exception as ex: logging.exception(ex) def handleError(self, chipError: PyChipError): self._resultError = chipError.code + + print("\n\n\n") + print(f"AsyncReadTransaction - handleError") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") def _handleSubscriptionEstablished(self, subscriptionId): if not self._future.done(): @@ -762,6 +844,20 @@ def _handleSubscriptionEstablished(self, subscriptionId): else: self._subscription_handler._onResubscriptionSucceededCb(self._subscription_handler) + print("\n\n\n") + print(f"AsyncReadTransaction - _handleSubscriptionEstablished") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") + def handleSubscriptionEstablished(self, subscriptionId): self._event_loop.call_soon_threadsafe( self._handleSubscriptionEstablished, subscriptionId) @@ -777,11 +873,52 @@ def handleResubscriptionAttempted(self, terminationCause: PyChipError, nextResub self._subscription_handler._onResubscriptionAttemptedCb, self._subscription_handler, terminationCause.code, nextResubscribeIntervalMsec) + print("\n\n\n") + print(f"AsyncReadTransaction - handleResubscriptionAttempted") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") + def _handleReportBegin(self): + print("\n\n\n") + print(f"AsyncReadTransaction - _handleReportBegin") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") pass - def _handleReportEnd(self): + def _handleReportEnd(self): self._cache.UpdateCachedData(self._changedPathSet) + + print("\n\n\n") + print(f"AsyncReadTransaction - _handleReportEnd") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") if (self._subscription_handler is not None): for change in self._changedPathSet: @@ -813,6 +950,20 @@ def _handleDone(self): else: self._future.set_result(AsyncReadTransaction.ReadResponse( attributes=self._cache.attributeCache, events=self._events, tlvAttributes=self._cache.attributeTLVCache)) + + print("\n\n\n") + print(f"AsyncReadTransaction - _handleDone") + print(f"self._event_loop: {self._event_loop}") + print(f"self._future: {self._future}") + print(f"self._subscription_handler: {self._subscription_handler}") + print(f"self._events: {self._events}") + print(f"self._devCtrl: {self._devCtrl}") + print(f"self._cache: {self._cache}") + print(f"self._changedPathSet: {self._changedPathSet}") + print(f"self._pReadClient: {self._pReadClient}") + print(f"self._pReadCallback: {self._pReadCallback}") + print(f"self._resultError: {self._resultError}") + print("\n\n\n") # # Decrement the ref on ourselves to match the increment that happened at allocation. @@ -823,14 +974,33 @@ def _handleDone(self): def handleDone(self): self._event_loop.call_soon_threadsafe(self._handleDone) - + def handleReportBegin(self): - pass - + self._handleReportBegin() + def handleReportEnd(self): - # self._event_loop.call_soon_threadsafe(self._handleReportEnd) self._handleReportEnd() + def _handleNotifySubscriptionStillActive(self): + pass + + def handleNotifySubscriptionStillActive(self): + print("\n\n\n\n\n\n\n\n\n\n\n") + print(f"closure.handleNotifySubscriptionStillActive") + print(f"\t\tAsyncReadTransaction - _handleReportBegin") + print(f"\t\tself._event_loop: {self._event_loop}") + print(f"\t\tself._future: {self._future}") + print(f"\t\tself._subscription_handler: {self._subscription_handler}") + print(f"\t\tself._events: {self._events}") + print(f"\t\tself._devCtrl: {self._devCtrl}") + print(f"\t\tself._cache: {self._cache}") + print(f"\t\tself._changedPathSet: {self._changedPathSet}") + print(f"\t\tself._pReadClient: {self._pReadClient}") + print(f"\t\tself._pReadCallback: {self._pReadCallback}") + print(f"\t\tself._resultError: {self._resultError}") + print("\n\n\n\n\n\n\n\n\n\n\n") + self._handleNotifySubscriptionStillActive() + class AsyncWriteTransaction: def __init__(self, future: Future, eventLoop): @@ -889,7 +1059,8 @@ def handleDone(self): None, py_object) _OnReportEndCallbackFunct = CFUNCTYPE( None, py_object) - +_OnNotifySubscriptionStillActiveCallbackFunct = CFUNCTYPE( + None, py_object) @_OnReadAttributeDataCallbackFunct def _OnReadAttributeDataCallback(closure, dataVersion: int, endpoint: int, cluster: int, attribute: int, status, data, len): @@ -937,6 +1108,11 @@ def _OnReportEndCallback(closure): closure.handleReportEnd() +@_OnNotifySubscriptionStillActiveCallbackFunct +def _OnNotifySubscriptionStillActiveCallback(closure): + closure.handleNotifySubscriptionStillActive() + + @_OnReadDoneCallbackFunct def _OnReadDoneCallback(closure): closure.handleDone() @@ -1208,14 +1384,15 @@ def Init(): _OnReadAttributeDataCallbackFunct, _OnReadEventDataCallbackFunct, _OnSubscriptionEstablishedCallbackFunct, _OnResubscriptionAttemptedCallbackFunct, _OnReadErrorCallbackFunct, _OnReadDoneCallbackFunct, - _OnReportBeginCallbackFunct, _OnReportEndCallbackFunct]) + _OnReportBeginCallbackFunct, _OnReportEndCallbackFunct, + _OnNotifySubscriptionStillActiveCallbackFunct]) handle.pychip_WriteClient_InitCallbacks( _OnWriteResponseCallback, _OnWriteErrorCallback, _OnWriteDoneCallback) handle.pychip_ReadClient_InitCallbacks( _OnReadAttributeDataCallback, _OnReadEventDataCallback, _OnSubscriptionEstablishedCallback, _OnResubscriptionAttemptedCallback, _OnReadErrorCallback, _OnReadDoneCallback, - _OnReportBeginCallback, _OnReportEndCallback) + _OnReportBeginCallback, _OnReportEndCallback, _OnNotifySubscriptionStillActiveCallback) _BuildAttributeIndex() _BuildClusterIndex() diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index b73b4a49b44d1f..0406dbb830f27c 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -83,6 +83,7 @@ using OnReadErrorCallback = void (*)(PyObject * appContext, PyChip using OnReadDoneCallback = void (*)(PyObject * appContext); using OnReportBeginCallback = void (*)(PyObject * appContext); using OnReportEndCallback = void (*)(PyObject * appContext); +using OnNotifySubscriptionStillActiveCallback = void (*)(PyObject * appContext); OnReadAttributeDataCallback gOnReadAttributeDataCallback = nullptr; OnReadEventDataCallback gOnReadEventDataCallback = nullptr; @@ -92,6 +93,7 @@ OnReadErrorCallback gOnReadErrorCallback = nullptr; OnReadDoneCallback gOnReadDoneCallback = nullptr; OnReportBeginCallback gOnReportBeginCallback = nullptr; OnReportBeginCallback gOnReportEndCallback = nullptr; +OnNotifySubscriptionStillActiveCallback gOnNotifySubscriptionStillActiveCallback = nullptr; void PythonResubscribePolicy(uint32_t aNumCumulativeRetries, uint32_t & aNextSubscriptionIntervalMsec, bool & aShouldResubscribe) { @@ -225,6 +227,11 @@ class ReadClientCallback : public ReadClient::Callback void OnReportEnd() override { gOnReportEndCallback(mAppContext); } + void NotifySubscriptionStillActive(const ReadClient & apReadClient) override + { + gOnNotifySubscriptionStillActiveCallback(mAppContext); + } + void OnDone(ReadClient *) override { gOnReadDoneCallback(mAppContext); @@ -326,16 +333,18 @@ void pychip_ReadClient_InitCallbacks(OnReadAttributeDataCallback onReadAttribute OnSubscriptionEstablishedCallback onSubscriptionEstablishedCallback, OnResubscriptionAttemptedCallback onResubscriptionAttemptedCallback, OnReadErrorCallback onReadErrorCallback, OnReadDoneCallback onReadDoneCallback, - OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback) + OnReportBeginCallback onReportBeginCallback, OnReportEndCallback onReportEndCallback, + OnNotifySubscriptionStillActiveCallback onNotifySubscriptionStillActiveCallback) { - gOnReadAttributeDataCallback = onReadAttributeDataCallback; - gOnReadEventDataCallback = onReadEventDataCallback; - gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback; - gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback; - gOnReadErrorCallback = onReadErrorCallback; - gOnReadDoneCallback = onReadDoneCallback; - gOnReportBeginCallback = onReportBeginCallback; - gOnReportEndCallback = onReportEndCallback; + gOnReadAttributeDataCallback = onReadAttributeDataCallback; + gOnReadEventDataCallback = onReadEventDataCallback; + gOnSubscriptionEstablishedCallback = onSubscriptionEstablishedCallback; + gOnResubscriptionAttemptedCallback = onResubscriptionAttemptedCallback; + gOnReadErrorCallback = onReadErrorCallback; + gOnReadDoneCallback = onReadDoneCallback; + gOnReportBeginCallback = onReportBeginCallback; + gOnReportEndCallback = onReportEndCallback; + gOnNotifySubscriptionStillActiveCallback = onNotifySubscriptionStillActiveCallback; } PyChipError pychip_WriteClient_WriteAttributes(void * appContext, DeviceProxy * device, size_t timedWriteTimeoutMsSizeT, diff --git a/src/python_testing/TC_IDM_4_3.py b/src/python_testing/TC_IDM_4_3.py index 873755716da0e1..675d81a186b616 100644 --- a/src/python_testing/TC_IDM_4_3.py +++ b/src/python_testing/TC_IDM_4_3.py @@ -115,10 +115,10 @@ async def test_TC_IDM_4_3(self): - # secs = 60 - # print(f"\n\n\n\n\nTime to sleep {secs} second(s)") - # time.sleep(secs) - # print(f"Rise and shine after {secs} second(s)\n\n\n\n\n") + secs = 60 + print(f"\n\n\n\n\nTime to sleep {secs} second(s)") + time.sleep(secs) + print(f"Rise and shine after {secs} second(s)\n\n\n\n\n")