From 21554938cf52edd00a3810c611dfebae847a54cf Mon Sep 17 00:00:00 2001 From: yzm157 <35371923+yzm157@users.noreply.github.com> Date: Tue, 30 May 2023 01:29:20 +0800 Subject: [PATCH] - fixed error event priority level (#26872) - fixed the EventHeader could not be generated when unsuccessful - fixed memory leak --- .../python/chip/clusters/Attribute.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index d007253a10cbf0..5967cbc386de8f 100644 --- a/src/controller/python/chip/clusters/Attribute.py +++ b/src/controller/python/chip/clusters/Attribute.py @@ -47,9 +47,9 @@ class EventTimestampType(Enum): @unique class EventPriority(Enum): - DEBUG = 1 - INFO = 2 - CRITICAL = 3 + DEBUG = 0 + INFO = 1 + CRITICAL = 2 @dataclass @@ -535,7 +535,7 @@ def Callback(transaction: SubscriptionTransaction, errorEncountered: int, nextRe self._onResubscriptionAttemptedCb = callback self._onResubscriptionAttemptedCb_isAsync = isAsync - def SetResubscriptionSucceededCallback(self, callback: Callback[[SubscriptionTransaction], None], isAsync=False): + def SetResubscriptionSucceededCallback(self, callback: Callable[[SubscriptionTransaction], None], isAsync=False): ''' Sets the callback function that gets invoked when a re-subscription attempt succeeds. The callback is expected to have the following signature: @@ -886,8 +886,13 @@ def _OnReadAttributeDataCallback(closure, dataVersion: int, endpoint: int, clust def _OnReadEventDataCallback(closure, endpoint: int, cluster: int, event: c_uint64, number: int, priority: int, timestamp: int, timestampType: int, data, len, status): dataBytes = ctypes.string_at(data, len) path = EventPath(ClusterId=cluster, EventId=event) - closure.handleEventData(EventHeader( - EndpointId=endpoint, ClusterId=cluster, EventId=event, EventNumber=number, Priority=EventPriority(priority), Timestamp=timestamp, TimestampType=EventTimestampType(timestampType)), path, dataBytes[:], status) + + # EventHeader is valid only when successful + eventHeader = None + if status == chip.interaction_model.Status.Success.value: + eventHeader = EventHeader( + EndpointId=endpoint, ClusterId=cluster, EventId=event, EventNumber=number, Priority=EventPriority(priority), Timestamp=timestamp, TimestampType=EventTimestampType(timestampType)) + closure.handleEventData(eventHeader, path, dataBytes[:], status) @_OnSubscriptionEstablishedCallbackFunct @@ -1079,10 +1084,6 @@ def Read(future: Future, eventLoop, device, devCtrl, attributes: List[AttributeP path = chip.interaction_model.EventPathIBstruct.build(path) readargs.append(ctypes.c_char_p(path)) - ctypes.pythonapi.Py_IncRef(ctypes.py_object(transaction)) - minInterval = 0 - maxInterval = 0 - readClientObj = ctypes.POINTER(c_void_p)() readCallbackObj = ctypes.POINTER(c_void_p)()