Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] SubscriptionTransaction export subscriptionId & GetReporting… #26623

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion src/controller/python/chip/clusters/Attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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!")
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 * 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, ...)
Expand Down