Skip to content

Commit

Permalink
[Python] Support commissioning with code on network only (#31000)
Browse files Browse the repository at this point in the history
* [Python] Support commissioning with code on network only

Add an additional parameter to support commissioning on network only.
This is useful when a manual pairing code is given and we know the
device is on the network already.

* Use consistent casing for newly added parameter
  • Loading branch information
agners authored and pull[bot] committed Jan 11, 2024
1 parent 04ddc94 commit 2918577
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
10 changes: 7 additions & 3 deletions src/controller/python/ChipDeviceController-ScriptBinding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#include <controller/CommissioningWindowOpener.h>
#include <controller/CurrentFabricRemover.h>
#include <controller/ExampleOperationalCredentialsIssuer.h>
#include <controller/SetUpCodePairer.h>

#include <controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h>
#include <controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h>
Expand Down Expand Up @@ -136,7 +137,7 @@ PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissio
PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr,
uint32_t setupPINCode, chip::NodeId nodeid);
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
chip::NodeId nodeid);
chip::NodeId nodeid, bool networkOnly);
PyChipError pychip_DeviceController_UnpairDevice(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId remoteDeviceId,
DeviceUnpairingCompleteFunct callback);
PyChipError pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size);
Expand Down Expand Up @@ -398,10 +399,13 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission
}

PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
chip::NodeId nodeid)
chip::NodeId nodeid, bool networkOnly)
{
chip::Controller::DiscoveryType discoveryType = chip::Controller::DiscoveryType::kAll;
sPairingDelegate.SetExpectingPairingComplete(true);
return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters));
if (networkOnly)
discoveryType = chip::Controller::DiscoveryType::kDiscoveryNetworkOnly;
return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters, discoveryType));
}

namespace {
Expand Down
6 changes: 3 additions & 3 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1580,7 +1580,7 @@ def _InitLib(self):
self._dmLib.pychip_DeviceController_ConnectIP.restype = PyChipError

self._dmLib.pychip_DeviceController_ConnectWithCode.argtypes = [
c_void_p, c_char_p, c_uint64]
c_void_p, c_char_p, c_uint64, c_bool]
self._dmLib.pychip_DeviceController_ConnectWithCode.restype = PyChipError

self._dmLib.pychip_DeviceController_UnpairDevice.argtypes = [
Expand Down Expand Up @@ -1893,7 +1893,7 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
return PyChipError(CHIP_ERROR_TIMEOUT)
return self._ChipStack.commissioningEventRes

def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError:
def CommissionWithCode(self, setupPayload: str, nodeid: int, networkOnly: bool = False) -> PyChipError:
''' Commission with the given nodeid from the setupPayload.
setupPayload may be a QR or manual code.
'''
Expand All @@ -1909,7 +1909,7 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError:

self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
self.devCtrl, setupPayload, nodeid)
self.devCtrl, setupPayload, nodeid, networkOnly)
)
if not self._ChipStack.commissioningCompleteEvent.isSet():
# Error 50 is a timeout
Expand Down

0 comments on commit 2918577

Please sign in to comment.