Skip to content

Commit 50500d2

Browse files
committed
[Python] Rename CallAsync to CallAsyncWithCallback
CallAsync continuously calls a callback function during the wait for the call. Rename the function to reflect that fact. This frees up CallAsync for an asyncio friendly implementation.
1 parent 5570be9 commit 50500d2

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def __init__(self, deviceProxy: ctypes.c_void_p, dmLib=None):
186186
def __del__(self):
187187
if (self._dmLib is not None and hasattr(builtins, 'chipStack') and builtins.chipStack is not None):
188188
# This destructor is called from any threading context, including on the Matter threading context.
189-
# So, we cannot call chipStack.Call or chipStack.CallAsync which waits for the posted work to
189+
# So, we cannot call chipStack.Call or chipStack.CallAsyncWithCallback which waits for the posted work to
190190
# actually be executed. Instead, we just post/schedule the work and move on.
191191
builtins.chipStack.PostTaskOnChipThread(lambda: self._dmLib.pychip_FreeOperationalDeviceProxy(self._deviceProxy))
192192

@@ -447,7 +447,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError:
447447

448448
self.state = DCState.COMMISSIONING
449449
self._enablePairingCompeleteCallback(True)
450-
self._ChipStack.CallAsync(
450+
self._ChipStack.CallAsyncWithCallback(
451451
lambda: self._dmLib.pychip_DeviceController_ConnectBLE(
452452
self.devCtrl, discriminator, setupPinCode, nodeid)
453453
).raise_on_error()
@@ -459,7 +459,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError:
459459
def UnpairDevice(self, nodeid: int):
460460
self.CheckIsActive()
461461

462-
return self._ChipStack.CallAsync(
462+
return self._ChipStack.CallAsyncWithCallback(
463463
lambda: self._dmLib.pychip_DeviceController_UnpairDevice(
464464
self.devCtrl, nodeid, self.cbHandleDeviceUnpairCompleteFunct)
465465
).raise_on_error()
@@ -498,7 +498,7 @@ def EstablishPASESessionBLE(self, setupPinCode: int, discriminator: int, nodeid:
498498

499499
self.state = DCState.RENDEZVOUS_ONGOING
500500
self._enablePairingCompeleteCallback(True)
501-
return self._ChipStack.CallAsync(
501+
return self._ChipStack.CallAsyncWithCallback(
502502
lambda: self._dmLib.pychip_DeviceController_EstablishPASESessionBLE(
503503
self.devCtrl, setupPinCode, discriminator, nodeid)
504504
)
@@ -508,7 +508,7 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
508508

509509
self.state = DCState.RENDEZVOUS_ONGOING
510510
self._enablePairingCompeleteCallback(True)
511-
return self._ChipStack.CallAsync(
511+
return self._ChipStack.CallAsyncWithCallback(
512512
lambda: self._dmLib.pychip_DeviceController_EstablishPASESessionIP(
513513
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid, port)
514514
)
@@ -518,7 +518,7 @@ def EstablishPASESession(self, setUpCode: str, nodeid: int):
518518

519519
self.state = DCState.RENDEZVOUS_ONGOING
520520
self._enablePairingCompeleteCallback(True)
521-
return self._ChipStack.CallAsync(
521+
return self._ChipStack.CallAsyncWithCallback(
522522
lambda: self._dmLib.pychip_DeviceController_EstablishPASESession(
523523
self.devCtrl, setUpCode.encode("utf-8"), nodeid)
524524
)
@@ -737,7 +737,7 @@ def OpenCommissioningWindow(self, nodeid: int, timeout: int, iteration: int,
737737
Returns CommissioningParameters
738738
'''
739739
self.CheckIsActive()
740-
self._ChipStack.CallAsync(
740+
self._ChipStack.CallAsyncWithCallback(
741741
lambda: self._dmLib.pychip_DeviceController_OpenCommissioningWindow(
742742
self.devCtrl, self.pairingDelegate, nodeid, timeout, iteration, discriminator, option)
743743
).raise_on_error()
@@ -1895,7 +1895,7 @@ def Commission(self, nodeid) -> PyChipError:
18951895
self._ChipStack.commissioningCompleteEvent.clear()
18961896
self.state = DCState.COMMISSIONING
18971897

1898-
self._ChipStack.CallAsync(
1898+
self._ChipStack.CallAsyncWithCallback(
18991899
lambda: self._dmLib.pychip_DeviceController_Commission(
19001900
self.devCtrl, nodeid)
19011901
)
@@ -2011,7 +2011,7 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
20112011
self._ChipStack.commissioningCompleteEvent.clear()
20122012

20132013
self._enablePairingCompeleteCallback(True)
2014-
self._ChipStack.CallAsync(
2014+
self._ChipStack.CallAsyncWithCallback(
20152015
lambda: self._dmLib.pychip_DeviceController_OnNetworkCommission(
20162016
self.devCtrl, self.pairingDelegate, nodeId, setupPinCode, int(filterType), str(filter).encode("utf-8") + b"\x00" if filter is not None else None, discoveryTimeoutMsec)
20172017
)
@@ -2035,7 +2035,7 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
20352035
self._ChipStack.commissioningCompleteEvent.clear()
20362036

20372037
self._enablePairingCompeleteCallback(True)
2038-
self._ChipStack.CallAsync(
2038+
self._ChipStack.CallAsyncWithCallback(
20392039
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
20402040
self.devCtrl, setupPayload, nodeid, discoveryType.value)
20412041
)
@@ -2055,7 +2055,7 @@ def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> PyChipErr
20552055
self._ChipStack.commissioningCompleteEvent.clear()
20562056

20572057
self._enablePairingCompeleteCallback(True)
2058-
self._ChipStack.CallAsync(
2058+
self._ChipStack.CallAsyncWithCallback(
20592059
lambda: self._dmLib.pychip_DeviceController_ConnectIP(
20602060
self.devCtrl, ipaddr.encode("utf-8"), setupPinCode, nodeid)
20612061
)
@@ -2069,7 +2069,7 @@ def IssueNOCChain(self, csr: Clusters.OperationalCredentials.Commands.CSRRespons
20692069
The NOC chain will be provided in TLV cert format."""
20702070
self.CheckIsActive()
20712071

2072-
return self._ChipStack.CallAsync(
2072+
return self._ChipStack.CallAsyncWithCallback(
20732073
lambda: self._dmLib.pychip_DeviceController_IssueNOCChain(
20742074
self.devCtrl, py_object(self), csr.NOCSRElements, len(csr.NOCSRElements), nodeId)
20752075
)

src/controller/python/chip/ChipStack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def Call(self, callFunct, timeoutMs: int = None):
367367
return self.callbackRes
368368
return res
369369

370-
def CallAsync(self, callFunct):
370+
def CallAsyncWithCallback(self, callFunct):
371371
'''Run a Python function on CHIP stack, and wait for the application specific response.
372372
This function is a wrapper of PostTaskOnChipThread, which includes some handling of application specific logics.
373373
Calling this function on CHIP on CHIP mainloop thread will cause deadlock.

0 commit comments

Comments
 (0)