Skip to content

Commit

Permalink
[Python] SubscriptionTransaction export subscriptionId & GetReporting…
Browse files Browse the repository at this point in the history
…Intervals
  • Loading branch information
tianfeng-yang committed May 17, 2023
1 parent 64bf867 commit 435737d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,24 @@ def OverrideLivenessTimeoutMs(self, timeoutMs: int):
lambda: handle.pychip_ReadClient_OverrideLivenessTimeout(self._readTransaction._pReadClient, timeoutMs)
)

def GetReportingIntervals(self) -> Tuple[int, int]:
'''
Retrieve the reporting intervals associated with an active subscription.
This should only be called if we're of subscription interaction type and after a subscription has been established.
'''
handle = chip.native.GetLibraryHandle()
handle.pychip_ReadClient_GetReportingIntervals.argtypes = [ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint16), ctypes.POINTER(ctypes.c_uint16)]
handle.pychip_ReadClient_GetReportingIntervals.restype = PyChipError

minInterval = ctypes.c_uint16(0)
maxInterval = ctypes.c_uint16(0)

builtins.chipStack.Call(
lambda: handle.pychip_ReadClient_GetReportingIntervals(self._readTransaction._pReadClient, ctypes.pointer(minInterval), ctypes.pointer(maxInterval))
).raise_on_error()

return minInterval.value, maxInterval.value

def SetResubscriptionAttemptedCallback(self, callback: Callable[[SubscriptionTransaction, int, int], None], isAsync=False):
'''
Sets the callback function that gets invoked anytime a re-subscription is attempted. The callback is expected
Expand Down Expand Up @@ -557,6 +575,10 @@ def OnEventChangeCb(self) -> Callable[[EventReadResult, SubscriptionTransaction]
def OnErrorCb(self) -> Callable[[int, SubscriptionTransaction], None]:
return self._onErrorCb

@property
def subscriptionId(self) -> int:
return self._subscriptionId

def Shutdown(self):
if (self._isDone):
print("Subscription was already terminated previously!")
Expand Down
8 changes: 8 additions & 0 deletions src/controller/python/chip/clusters/attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,14 @@ void pychip_ReadClient_OverrideLivenessTimeout(ReadClient * pReadClient, uint32_
pReadClient->OverrideLivenessTimeout(System::Clock::Milliseconds32(livenessTimeoutMs));
}

PyChipError pychip_ReadClient_GetReportingIntervals(ReadClient * pReadClient, uint16_t * minInterval, uint16_t * maxInterval)
{
VerifyOrDie(pReadClient != nullptr);
CHIP_ERROR err = pReadClient->GetReportingIntervals(*minInterval, *maxInterval);

return ToPyChipError(err);
}

PyChipError pychip_ReadClient_Read(void * appContext, ReadClient ** pReadClient, ReadClientCallback ** pCallback,
DeviceProxy * device, uint8_t * readParamsBuf, size_t numAttributePaths,
size_t numDataversionFilters, size_t numEventPaths, uint64_t * eventNumberFilter, ...)
Expand Down

0 comments on commit 435737d

Please sign in to comment.