From 10530382d90c25907cf6e3eed31367fb5e2a243b Mon Sep 17 00:00:00 2001 From: tianfeng-yang <130436698+tianfeng-yang@users.noreply.github.com> Date: Thu, 25 May 2023 09:12:15 +0800 Subject: [PATCH] =?UTF-8?q?[Python]=20SubscriptionTransaction=20export=20s?= =?UTF-8?q?ubscriptionId=20&=20GetReporting=E2=80=A6=20(#26623)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [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 --- .../python/chip/clusters/Attribute.py | 26 ++++++++++++++++++- .../python/chip/clusters/attribute.cpp | 8 ++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/src/controller/python/chip/clusters/Attribute.py b/src/controller/python/chip/clusters/Attribute.py index 3660d31234f0fe..d007253a10cbf0 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 @@ def OverrideLivenessTimeoutMs(self, timeoutMs: int): 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 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!") diff --git a/src/controller/python/chip/clusters/attribute.cpp b/src/controller/python/chip/clusters/attribute.cpp index d97faf5cdaaad8..d30655b5daf177 100644 --- a/src/controller/python/chip/clusters/attribute.cpp +++ b/src/controller/python/chip/clusters/attribute.cpp @@ -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 * 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, ...)