diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index a3a9b3040223be..4d02f0b03eba00 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -1013,12 +1013,8 @@ def GetRemoteSessionParameters(self, nodeid) -> typing.Optional[SessionParameter sessionParametersStruct = SessionParametersStruct.parse(b'\x00' * SessionParametersStruct.sizeof()) sessionParametersByteArray = SessionParametersStruct.build(sessionParametersStruct) device = self.GetConnectedDeviceSync(nodeid) - res = self._ChipStack.Call(lambda: self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters( - device.deviceProxy, ctypes.c_char_p(sessionParametersByteArray))) - - # 0 is CHIP_NO_ERROR - if res != 0: - return None + self._ChipStack.Call(lambda: self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters( + device.deviceProxy, ctypes.c_char_p(sessionParametersByteArray))).raise_on_error() sessionParametersStruct = SessionParametersStruct.parse(sessionParametersByteArray) return SessionParameters( @@ -1804,6 +1800,9 @@ def _InitLib(self): self._dmLib.pychip_CheckInDelegate_SetOnCheckInCompleteCallback(_OnCheckInComplete) + self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters.restype = PyChipError + self._dmLib.pychip_DeviceProxy_GetRemoteSessionParameters.argtypes = [c_void_p, c_char_p] + class ChipDeviceController(ChipDeviceControllerBase): ''' The ChipDeviceCommissioner binding, named as ChipDeviceController diff --git a/src/controller/python/chip/discovery/__init__.py b/src/controller/python/chip/discovery/__init__.py index c400d97542a69d..a25fb490007824 100644 --- a/src/controller/python/chip/discovery/__init__.py +++ b/src/controller/python/chip/discovery/__init__.py @@ -236,8 +236,7 @@ def FindAddressAsync(fabricid: int, nodeid: int, callback, timeout_ms=1000): ) res = _GetDiscoveryLibraryHandle().pychip_discovery_resolve(fabricid, nodeid) - if res != 0: - raise Exception("Failed to start node resolution") + res.raise_on_error() class _SyncAddressFinder: diff --git a/src/controller/python/chip/interaction_model/delegate.py b/src/controller/python/chip/interaction_model/delegate.py index 14512000a63bf5..4741e5f2f74482 100644 --- a/src/controller/python/chip/interaction_model/delegate.py +++ b/src/controller/python/chip/interaction_model/delegate.py @@ -330,7 +330,7 @@ def InitIMDelegate(): setter.Set("pychip_InteractionModelDelegate_SetCommandResponseErrorCallback", None, [ _OnCommandResponseFunct]) setter.Set("pychip_InteractionModel_GetCommandSenderHandle", - c_uint32, [ctypes.POINTER(c_uint64)]) + chip.native.PyChipError, [ctypes.POINTER(c_uint64)]) setter.Set("pychip_InteractionModelDelegate_SetOnWriteResponseStatusCallback", None, [ _OnWriteResponseStatusFunct]) @@ -389,10 +389,8 @@ def WaitCommandIndexStatus(commandHandle: int, commandIndex: int): def GetCommandSenderHandle() -> int: handle = chip.native.GetLibraryHandle() resPointer = c_uint64() - res = handle.pychip_InteractionModel_GetCommandSenderHandle( - ctypes.pointer(resPointer)) - if res != 0: - raise chip.exceptions.ChipStackError(res) + handle.pychip_InteractionModel_GetCommandSenderHandle( + ctypes.pointer(resPointer)).raise_on_error() ClearCommandStatus(resPointer.value) return resPointer.value diff --git a/src/controller/python/chip/native/__init__.py b/src/controller/python/chip/native/__init__.py index ce8b7620f498f9..26295c2011a26b 100644 --- a/src/controller/python/chip/native/__init__.py +++ b/src/controller/python/chip/native/__init__.py @@ -199,7 +199,7 @@ def __init__(self, handle): def Set(self, methodName: str, resultType, argumentTypes: list): method = getattr(self.handle, methodName) method.restype = resultType - method.argtype = argumentTypes + method.argtypes = argumentTypes @dataclass diff --git a/src/controller/python/chip/setup_payload/setup_payload.py b/src/controller/python/chip/setup_payload/setup_payload.py index 1f70983ad9a7ff..fb77c0b7cc60c4 100644 --- a/src/controller/python/chip/setup_payload/setup_payload.py +++ b/src/controller/python/chip/setup_payload/setup_payload.py @@ -18,7 +18,7 @@ from typing import Optional from chip.exceptions import ChipStackError -from chip.native import GetLibraryHandle, NativeLibraryHandleMethodArguments +from chip.native import GetLibraryHandle, NativeLibraryHandleMethodArguments, PyChipError class SetupPayload: @@ -46,34 +46,23 @@ def AddVendorAttribute(tag, value): def ParseQrCode(self, qrCode: str): self.Clear() - err = self.chipLib.pychip_SetupPayload_ParseQrCode(qrCode.upper().encode(), + self.chipLib.pychip_SetupPayload_ParseQrCode(qrCode.upper().encode(), self.attribute_visitor, - self.vendor_attribute_visitor) - - if err != 0: - raise ChipStackError(err) - - return self + self.vendor_attribute_visitor).raise_on_error() def ParseManualPairingCode(self, manualPairingCode: str): self.Clear() - err = self.chipLib.pychip_SetupPayload_ParseManualPairingCode(manualPairingCode.encode(), + self.chipLib.pychip_SetupPayload_ParseManualPairingCode(manualPairingCode.encode(), self.attribute_visitor, - self.vendor_attribute_visitor) - - if err != 0: - raise ChipStackError(err) + self.vendor_attribute_visitor).raise_on_error() return self # DEPRECATED def PrintOnboardingCodes(self, passcode, vendorId, productId, discriminator, customFlow, capabilities, version): self.Clear() - err = self.chipLib.pychip_SetupPayload_PrintOnboardingCodes( - passcode, vendorId, productId, discriminator, customFlow, capabilities, version) - - if err != 0: - raise ChipStackError(err) + self.chipLib.pychip_SetupPayload_PrintOnboardingCodes( + passcode, vendorId, productId, discriminator, customFlow, capabilities, version).raise_on_error() # DEPRECATED def Print(self): @@ -106,17 +95,17 @@ def __DecorateValue(self, name, value): return None def __InitNativeFunctions(self, chipLib): - if chipLib.pychip_SetupPayload_ParseQrCode is not None: + if chipLib.pychip_SetupPayload_ParseQrCode.argtypes is not None: return setter = NativeLibraryHandleMethodArguments(chipLib) setter.Set("pychip_SetupPayload_ParseQrCode", - c_int32, + PyChipError, [c_char_p, SetupPayload.AttributeVisitor, SetupPayload.VendorAttributeVisitor]) setter.Set("pychip_SetupPayload_ParseManualPairingCode", - c_int32, + PyChipError, [c_char_p, SetupPayload.AttributeVisitor, SetupPayload.VendorAttributeVisitor]) setter.Set("pychip_SetupPayload_PrintOnboardingCodes", - c_int32, + PyChipError, [c_uint32, c_uint16, c_uint16, c_uint16, c_uint8, c_uint8, c_uint8]) # Getters from parsed contents.