Skip to content

Commit 1053038

Browse files
tianfeng-yangrestyled-commits
authored andcommitted
[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>
1 parent 54e704e commit 1053038

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from ctypes import CFUNCTYPE, c_size_t, c_uint8, c_uint16, c_uint32, c_uint64, c_void_p, py_object
2828
from dataclasses import dataclass, field
2929
from enum import Enum, unique
30-
from typing import Any, Callable, Dict, List, Optional, Union
30+
from typing import Any, Callable, Dict, List, Optional, Tuple, Union
3131

3232
import chip.exceptions
3333
import chip.interaction_model
@@ -503,6 +503,26 @@ def OverrideLivenessTimeoutMs(self, timeoutMs: int):
503503
lambda: handle.pychip_ReadClient_OverrideLivenessTimeout(self._readTransaction._pReadClient, timeoutMs)
504504
)
505505

506+
def GetReportingIntervalsSeconds(self) -> Tuple[int, int]:
507+
'''
508+
Retrieve the reporting intervals associated with an active subscription.
509+
This should only be called if we're of subscription interaction type and after a subscription has been established.
510+
'''
511+
handle = chip.native.GetLibraryHandle()
512+
handle.pychip_ReadClient_GetReportingIntervals.argtypes = [
513+
ctypes.c_void_p, ctypes.POINTER(ctypes.c_uint16), ctypes.POINTER(ctypes.c_uint16)]
514+
handle.pychip_ReadClient_GetReportingIntervals.restype = PyChipError
515+
516+
minIntervalSec = ctypes.c_uint16(0)
517+
maxIntervalSec = ctypes.c_uint16(0)
518+
519+
builtins.chipStack.Call(
520+
lambda: handle.pychip_ReadClient_GetReportingIntervals(
521+
self._readTransaction._pReadClient, ctypes.pointer(minIntervalSec), ctypes.pointer(maxIntervalSec))
522+
).raise_on_error()
523+
524+
return minIntervalSec.value, maxIntervalSec.value
525+
506526
def SetResubscriptionAttemptedCallback(self, callback: Callable[[SubscriptionTransaction, int, int], None], isAsync=False):
507527
'''
508528
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]
557577
def OnErrorCb(self) -> Callable[[int, SubscriptionTransaction], None]:
558578
return self._onErrorCb
559579

580+
@property
581+
def subscriptionId(self) -> int:
582+
return self._subscriptionId
583+
560584
def Shutdown(self):
561585
if (self._isDone):
562586
print("Subscription was already terminated previously!")

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

+8
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,14 @@ void pychip_ReadClient_OverrideLivenessTimeout(ReadClient * pReadClient, uint32_
467467
pReadClient->OverrideLivenessTimeout(System::Clock::Milliseconds32(livenessTimeoutMs));
468468
}
469469

470+
PyChipError pychip_ReadClient_GetReportingIntervals(ReadClient * pReadClient, uint16_t * minIntervalSec, uint16_t * maxIntervalSec)
471+
{
472+
VerifyOrDie(pReadClient != nullptr);
473+
CHIP_ERROR err = pReadClient->GetReportingIntervals(*minIntervalSec, *maxIntervalSec);
474+
475+
return ToPyChipError(err);
476+
}
477+
470478
PyChipError pychip_ReadClient_Read(void * appContext, ReadClient ** pReadClient, ReadClientCallback ** pCallback,
471479
DeviceProxy * device, uint8_t * readParamsBuf, size_t numAttributePaths,
472480
size_t numDataversionFilters, size_t numEventPaths, uint64_t * eventNumberFilter, ...)

0 commit comments

Comments
 (0)