diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py index 42ee9e6f535197..f9aee9ca29d286 100644 --- a/src/controller/python/chip/ChipDeviceCtrl.py +++ b/src/controller/python/chip/ChipDeviceCtrl.py @@ -360,7 +360,10 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError): logging.exception("HandleCommissioningComplete called unexpectedly") return - self._commissioning_complete_future.set_result(err) + if err.is_success: + self._commissioning_complete_future.set_result(None) + else: + self._commissioning_complete_future.set_exception(err.to_exception()) def HandleFabricCheck(nodeId): self.fabricCheckNodeId = nodeId @@ -533,7 +536,7 @@ def IsConnected(self): self.devCtrl) ) - def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError: + def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> None: self.CheckIsActive() self._commissioning_complete_future = concurrent.futures.Future() @@ -545,11 +548,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError: self.devCtrl, discriminator, setupPinCode, nodeid) ).raise_on_error() - # TODO: Change return None. Only returning on success is not useful. - # but that is what the previous implementation did. - res = self._commissioning_complete_future.result() - res.raise_on_error() - return res + return self._commissioning_complete_future.result() finally: self._commissioning_complete_future = None @@ -1856,17 +1855,16 @@ def caIndex(self) -> int: def fabricAdmin(self) -> FabricAdmin: return self._fabricAdmin - def Commission(self, nodeid) -> PyChipError: + def Commission(self, nodeid) -> None: ''' Start the auto-commissioning process on a node after establishing a PASE connection. This function is intended to be used in conjunction with `EstablishPASESessionBLE` or `EstablishPASESessionIP`. It can be called either before or after the DevicePairingDelegate receives the OnPairingComplete call. Commissioners that want to perform simple - auto-commissioning should use the supplied "PairDevice" functions above, which will + auto-commissioning should use the supplied "CommissionWithCode" function, which will establish the PASE connection and commission automatically. - Return: - bool: True if successful, False otherwise. + Raises a ChipStackError on failure. ''' self.CheckIsActive() @@ -1991,7 +1989,7 @@ def GetFabricCheckResult(self) -> int: return self.fabricCheckNodeId def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, - filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, discoveryTimeoutMsec: int = 30000) -> PyChipError: + filterType: DiscoveryFilterType = DiscoveryFilterType.NONE, filter: typing.Any = None, discoveryTimeoutMsec: int = 30000) -> None: ''' Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery. Supported filters are: @@ -2007,6 +2005,8 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, DiscoveryFilterType.COMPRESSED_FABRIC_ID The filter can be an integer, a string or None depending on the actual type of selected filter. + + Raises a ChipStackError on failure. ''' self.CheckIsActive() @@ -2026,9 +2026,11 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int, finally: self._commissioning_complete_future = None - def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: DiscoveryType = DiscoveryType.DISCOVERY_ALL) -> PyChipError: + def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: DiscoveryType = DiscoveryType.DISCOVERY_ALL) -> None: ''' Commission with the given nodeid from the setupPayload. setupPayload may be a QR or manual code. + + Raises a ChipStackError on failure. ''' self.CheckIsActive() @@ -2047,8 +2049,11 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc finally: self._commissioning_complete_future = None - def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> PyChipError: - """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode` """ + def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> None: + """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode` + + Raises a ChipStackError on failure. + """ self.CheckIsActive() self._commissioning_complete_future = concurrent.futures.Future()