Skip to content

Commit

Permalink
[Python] SubscriptionTransaction export subscriptionId & GetReporting… (
Browse files Browse the repository at this point in the history
#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 <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jul 22, 2023
1 parent 54e704e commit 1053038
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
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

0 comments on commit 1053038

Please sign in to comment.