Skip to content

Commit f4635db

Browse files
committed
[Python] Use CallAsync where appropriate
1 parent f36bf83 commit f4635db

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

src/controller/python/chip/ChipDeviceCtrl.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -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],

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)