Skip to content

Commit 1cb49b0

Browse files
committed
export GetSubscriptionTimeout API
1 parent 27abedf commit 1cb49b0

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/controller/python/chip/clusters/Attribute.py

+16
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,22 @@ def GetReportingIntervalsSeconds(self) -> Tuple[int, int]:
520520

521521
return minIntervalSec.value, maxIntervalSec.value
522522

523+
def GetSubscriptionTimeout(self) -> int:
524+
'''
525+
Returns the timeout after which we consider the subscription to have
526+
dropped, if we have received no messages within that amount of time.
527+
528+
Returns 0 if a subscription has not yet been established (and
529+
hence the MaxInterval is not yet known), or if the subscription session
530+
is gone and hence the relevant MRP parameters can no longer be determined.
531+
'''
532+
timeoutMs = ctypes.c_uint32(0)
533+
handle = chip.native.GetLibraryHandle()
534+
builtins.chipStack.Call(
535+
lambda: handle.pychip_ReadClient_GetSubscriptionTimeout(self._readTransaction._pReadClient, ctypes.pointer(timeoutMs))
536+
)
537+
return timeoutMs.value
538+
523539
def SetResubscriptionAttemptedCallback(self, callback: Callable[[SubscriptionTransaction, int, int], None], isAsync=False):
524540
'''
525541
Sets the callback function that gets invoked anytime a re-subscription is attempted. The callback is expected

src/controller/python/chip/clusters/attribute.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,22 @@ PyChipError pychip_ReadClient_GetReportingIntervals(ReadClient * pReadClient, ui
476476
return ToPyChipError(err);
477477
}
478478

479+
void pychip_ReadClient_GetSubscriptionTimeout(ReadClient * pReadClient, uint32_t * milliSec)
480+
{
481+
VerifyOrDie(pReadClient != nullptr);
482+
483+
Optional<System::Clock::Timeout> duration = pReadClient->GetSubscriptionTimeout();
484+
485+
// The return value of GetSubscriptionTimeout cannot be 0
486+
// so milliSec=0 can be considered as the subscription has been abnormal.
487+
*milliSec = 0;
488+
if (duration.HasValue())
489+
{
490+
System::Clock::Milliseconds32 msec = std::chrono::duration_cast<System::Clock::Milliseconds32>(duration.Value());
491+
*milliSec = msec.count();
492+
}
493+
}
494+
479495
PyChipError pychip_ReadClient_Read(void * appContext, ReadClient ** pReadClient, ReadClientCallback ** pCallback,
480496
DeviceProxy * device, uint8_t * readParamsBuf, void ** attributePathsFromPython,
481497
size_t numAttributePaths, void ** dataversionFiltersFromPython, size_t numDataversionFilters,

0 commit comments

Comments
 (0)