Skip to content

Commit 44ea891

Browse files
committed
[Python] Use CallAsync where appropriate
1 parent 5e40de3 commit 44ea891

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ async def GetConnectedDevice(self, nodeid, allowPASE: bool = True, timeoutMs: in
858858

859859
if allowPASE:
860860
returnDevice = c_void_p(None)
861-
res = self._ChipStack.Call(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
861+
res = await self._ChipStack.CallAsync(lambda: self._dmLib.pychip_GetDeviceBeingCommissioned(
862862
self.devCtrl, nodeid, byref(returnDevice)), timeoutMs)
863863
if res.is_success:
864864
logging.info('Using PASE connection')
@@ -888,11 +888,11 @@ def deviceAvailable(self, device, err):
888888

889889
closure = DeviceAvailableClosure(eventLoop, future)
890890
ctypes.pythonapi.Py_IncRef(ctypes.py_object(closure))
891-
self._ChipStack.Call(lambda: self._dmLib.pychip_GetConnectedDeviceByNodeId(
891+
await self._ChipStack.CallAsync(lambda: self._dmLib.pychip_GetConnectedDeviceByNodeId(
892892
self.devCtrl, nodeid, ctypes.py_object(closure), _DeviceAvailableCallback),
893893
timeoutMs).raise_on_error()
894894

895-
# The callback might have been received synchronously (during self._ChipStack.Call()).
895+
# The callback might have been received synchronously (during self._ChipStack.CallAsync()).
896896
# In that case the Future has already been set it will return immediately
897897
if timeoutMs is not None:
898898
timeout = float(timeoutMs) / 1000
@@ -1020,13 +1020,14 @@ async def SendCommand(self, nodeid: int, endpoint: int, payload: ClusterObjects.
10201020
future = eventLoop.create_future()
10211021

10221022
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
1023-
ClusterCommand.SendCommand(
1023+
res = await ClusterCommand.SendCommand(
10241024
future, eventLoop, responseType, device.deviceProxy, ClusterCommand.CommandPath(
10251025
EndpointId=endpoint,
10261026
ClusterId=payload.cluster_id,
10271027
CommandId=payload.command_id,
10281028
), payload, timedRequestTimeoutMs=timedRequestTimeoutMs,
1029-
interactionTimeoutMs=interactionTimeoutMs, busyWaitMs=busyWaitMs, suppressResponse=suppressResponse).raise_on_error()
1029+
interactionTimeoutMs=interactionTimeoutMs, busyWaitMs=busyWaitMs, suppressResponse=suppressResponse)
1030+
res.raise_on_error()
10301031
return await future
10311032

10321033
async def SendBatchCommands(self, nodeid: int, commands: typing.List[ClusterCommand.InvokeRequestInfo],
@@ -1062,10 +1063,11 @@ async def SendBatchCommands(self, nodeid: int, commands: typing.List[ClusterComm
10621063

10631064
device = await self.GetConnectedDevice(nodeid, timeoutMs=interactionTimeoutMs)
10641065

1065-
ClusterCommand.SendBatchCommands(
1066+
res = await ClusterCommand.SendBatchCommands(
10661067
future, eventLoop, device.deviceProxy, commands,
10671068
timedRequestTimeoutMs=timedRequestTimeoutMs,
1068-
interactionTimeoutMs=interactionTimeoutMs, busyWaitMs=busyWaitMs, suppressResponse=suppressResponse).raise_on_error()
1069+
interactionTimeoutMs=interactionTimeoutMs, busyWaitMs=busyWaitMs, suppressResponse=suppressResponse)
1070+
res.raise_on_error()
10691071
return await future
10701072

10711073
def SendGroupCommand(self, groupid: int, payload: ClusterObjects.ClusterCommand, busyWaitMs: typing.Union[None, int] = None):

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,9 @@ def TestOnlySendCommandTimedRequestFlagWithNoTimedInvoke(future: Future, eventLo
291291
))
292292

293293

294-
def SendCommand(future: Future, eventLoop, responseType: Type, device, commandPath: CommandPath, payload: ClusterCommand,
295-
timedRequestTimeoutMs: Union[None, int] = None, interactionTimeoutMs: Union[None, int] = None, busyWaitMs: Union[None, int] = None,
296-
suppressResponse: Union[None, bool] = None) -> PyChipError:
294+
async def SendCommand(future: Future, eventLoop, responseType: Type, device, commandPath: CommandPath, payload: ClusterCommand,
295+
timedRequestTimeoutMs: Union[None, int] = None, interactionTimeoutMs: Union[None, int] = None,
296+
busyWaitMs: Union[None, int] = None, suppressResponse: Union[None, bool] = None) -> PyChipError:
297297
''' Send a cluster-object encapsulated command to a device and does the following:
298298
- On receipt of a successful data response, returns the cluster-object equivalent through the provided future.
299299
- None (on a successful response containing no data)
@@ -316,7 +316,7 @@ def SendCommand(future: Future, eventLoop, responseType: Type, device, commandPa
316316

317317
payloadTLV = payload.ToTLV()
318318
ctypes.pythonapi.Py_IncRef(ctypes.py_object(transaction))
319-
return builtins.chipStack.Call(
319+
return await builtins.chipStack.CallAsync(
320320
lambda: handle.pychip_CommandSender_SendCommand(
321321
ctypes.py_object(transaction), device,
322322
c_uint16(0 if timedRequestTimeoutMs is None else timedRequestTimeoutMs), commandPath.EndpointId,
@@ -353,9 +353,9 @@ def _BuildPyInvokeRequestData(commands: List[InvokeRequestInfo], timedRequestTim
353353
return pyBatchCommandsData
354354

355355

356-
def SendBatchCommands(future: Future, eventLoop, device, commands: List[InvokeRequestInfo],
357-
timedRequestTimeoutMs: Optional[int] = None, interactionTimeoutMs: Optional[int] = None, busyWaitMs: Optional[int] = None,
358-
suppressResponse: Optional[bool] = None) -> PyChipError:
356+
async def SendBatchCommands(future: Future, eventLoop, device, commands: List[InvokeRequestInfo],
357+
timedRequestTimeoutMs: Optional[int] = None, interactionTimeoutMs: Optional[int] = None,
358+
busyWaitMs: Optional[int] = None, suppressResponse: Optional[bool] = None) -> PyChipError:
359359
''' Initiates an InvokeInteraction with the batch commands provided.
360360
361361
Arguments:
@@ -388,7 +388,7 @@ def SendBatchCommands(future: Future, eventLoop, device, commands: List[InvokeRe
388388
transaction = AsyncBatchCommandsTransaction(future, eventLoop, responseTypes)
389389
ctypes.pythonapi.Py_IncRef(ctypes.py_object(transaction))
390390

391-
return builtins.chipStack.Call(
391+
return await builtins.chipStack.CallAsync(
392392
lambda: handle.pychip_CommandSender_SendBatchCommands(
393393
py_object(transaction), device,
394394
c_uint16(0 if timedRequestTimeoutMs is None else timedRequestTimeoutMs),

0 commit comments

Comments
 (0)