From 2dfa1de8facebbacef1a7ffc635410aaca18534a Mon Sep 17 00:00:00 2001 From: Song Guo Date: Wed, 9 Jun 2021 22:09:14 +0800 Subject: [PATCH] [python] Raise exceptions when the controller failed to send commands (#7485) --- src/controller/python/chip/clusters/CHIPClusters.py | 4 +++- src/controller/python/templates/python-CHIPClusters-py.zapt | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/controller/python/chip/clusters/CHIPClusters.py b/src/controller/python/chip/clusters/CHIPClusters.py index 7fac809e115b6e..6681ef4bafd04a 100644 --- a/src/controller/python/chip/clusters/CHIPClusters.py +++ b/src/controller/python/chip/clusters/CHIPClusters.py @@ -958,7 +958,9 @@ def SendCommand(self, device: ctypes.c_void_p, cluster: str, command: str, endpo if not func: raise UnknownCommand(cluster, command) funcCaller = self._ChipStack.Call if imEnabled else self._ChipStack.CallAsync - funcCaller(lambda: func(device, endpoint, groupid, **args)) + res = funcCaller(lambda: func(device, endpoint, groupid, **args)) + if res != 0: + raise self._ChipStack.ErrorToException(res) def ReadAttribute(self, device: ctypes.c_void_p, cluster: str, attribute: str, endpoint: int, groupid: int, imEnabled): func = getattr(self, "Cluster{}_ReadAttribute{}".format(cluster, attribute), None) diff --git a/src/controller/python/templates/python-CHIPClusters-py.zapt b/src/controller/python/templates/python-CHIPClusters-py.zapt index 7badb8e85b0a50..9636349faed269 100644 --- a/src/controller/python/templates/python-CHIPClusters-py.zapt +++ b/src/controller/python/templates/python-CHIPClusters-py.zapt @@ -50,7 +50,9 @@ class ChipClusters: if not func: raise UnknownCommand(cluster, command) funcCaller = self._ChipStack.Call if imEnabled else self._ChipStack.CallAsync - funcCaller(lambda: func(device, endpoint, groupid, **args)) + res = funcCaller(lambda: func(device, endpoint, groupid, **args)) + if res != 0: + raise self._ChipStack.ErrorToException(res) def ReadAttribute(self, device: ctypes.c_void_p, cluster: str, attribute: str, endpoint: int, groupid: int, imEnabled): func = getattr(self, "Cluster{}_ReadAttribute{}".format(cluster, attribute), None)