[Python] SubscriptionTransaction export subscriptionId & GetReporting… (#26623)
* [Python] SubscriptionTransaction export subscriptionId & GetReportingIntervals
* Restyled by autopep8
* FIX CI
* Restyled by isort
* [Python] Renamed GetReportingIntervals to GetReportingIntervalsSeconds
* variable naming add time unit
---------
Co-authored-by: Restyled.io <commits@restyled.io>
diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py
index 3660d31..d007253 100644
--- a/src/controller/python/chip/clusters/Attribute.py
+++ b/src/controller/python/chip/clusters/Attribute.py
@@ -27,7 +27,7 @@
from ctypes import CFUNCTYPE, c_size_t, c_uint8, c_uint16, c_uint32, c_uint64, c_void_p, py_object
from dataclasses import dataclass, field
from enum import Enum, unique
-from typing import Any, Callable, Dict, List, Optional, Union
+from typing import Any, Callable, Dict, List, Optional, Tuple, Union
import chip.exceptions
import chip.interaction_model
@@ -503,6 +503,26 @@
lambda: handle.pychip_ReadClient_OverrideLivenessTimeout(self._readTransaction._pReadClient, timeoutMs)
)
+ def GetReportingIntervalsSeconds(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
+
+ minIntervalSec = ctypes.c_uint16(0)
+ maxIntervalSec = ctypes.c_uint16(0)
+
+ builtins.chipStack.Call(
+ lambda: handle.pychip_ReadClient_GetReportingIntervals(
+ self._readTransaction._pReadClient, ctypes.pointer(minIntervalSec), ctypes.pointer(maxIntervalSec))
+ ).raise_on_error()
+
+ return minIntervalSec.value, maxIntervalSec.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
@@ -557,6 +577,10 @@
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!")
diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp
index d97faf5..d30655b 100644
--- a/src/controller/python/chip/clusters/attribute.cpp
+++ b/src/controller/python/chip/clusters/attribute.cpp
@@ -467,6 +467,14 @@
pReadClient->OverrideLivenessTimeout(System::Clock::Milliseconds32(livenessTimeoutMs));
}
+PyChipError pychip_ReadClient_GetReportingIntervals(ReadClient * pReadClient, uint16_t * minIntervalSec, uint16_t * maxIntervalSec)
+{
+ VerifyOrDie(pReadClient != nullptr);
+ CHIP_ERROR err = pReadClient->GetReportingIntervals(*minIntervalSec, *maxIntervalSec);
+
+ 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, ...)