Skip to content

Commit 497e3a7

Browse files
committed
Support commissioning with manual pairing code on network only
1 parent dbb960a commit 497e3a7

1 file changed

+90
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
From 7960dbdfff87939cd655d96752ef7cc511a9000e Mon Sep 17 00:00:00 2001
2+
Message-ID: <7960dbdfff87939cd655d96752ef7cc511a9000e.1703058900.git.stefan@agner.ch>
3+
From: Stefan Agner <[email protected]>
4+
Date: Thu, 14 Dec 2023 13:33:05 +0100
5+
Subject: [PATCH] [Python] Support commissioning with code on network only
6+
(#31000)
7+
8+
* [Python] Support commissioning with code on network only
9+
10+
Add an additional parameter to support commissioning on network only.
11+
This is useful when a manual pairing code is given and we know the
12+
device is on the network already.
13+
14+
* Use consistent casing for newly added parameter
15+
---
16+
.../python/ChipDeviceController-ScriptBinding.cpp | 10 +++++++---
17+
src/controller/python/chip/ChipDeviceCtrl.py | 6 +++---
18+
2 files changed, 10 insertions(+), 6 deletions(-)
19+
20+
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
21+
index 3c01910729..4979da8acd 100644
22+
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp
23+
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp
24+
@@ -50,6 +50,7 @@
25+
#include <controller/CommissioningWindowOpener.h>
26+
#include <controller/CurrentFabricRemover.h>
27+
#include <controller/ExampleOperationalCredentialsIssuer.h>
28+
+#include <controller/SetUpCodePairer.h>
29+
30+
#include <controller/python/ChipDeviceController-ScriptDevicePairingDelegate.h>
31+
#include <controller/python/ChipDeviceController-ScriptPairingDeviceDiscoveryDelegate.h>
32+
@@ -136,7 +137,7 @@ PyChipError pychip_DeviceController_ConnectBLE(chip::Controller::DeviceCommissio
33+
PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommissioner * devCtrl, const char * peerAddrStr,
34+
uint32_t setupPINCode, chip::NodeId nodeid);
35+
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
36+
- chip::NodeId nodeid);
37+
+ chip::NodeId nodeid, bool networkOnly);
38+
PyChipError pychip_DeviceController_UnpairDevice(chip::Controller::DeviceCommissioner * devCtrl, chip::NodeId remoteDeviceId,
39+
DeviceUnpairingCompleteFunct callback);
40+
PyChipError pychip_DeviceController_SetThreadOperationalDataset(const char * threadOperationalDataset, uint32_t size);
41+
@@ -398,10 +399,13 @@ PyChipError pychip_DeviceController_ConnectIP(chip::Controller::DeviceCommission
42+
}
43+
44+
PyChipError pychip_DeviceController_ConnectWithCode(chip::Controller::DeviceCommissioner * devCtrl, const char * onboardingPayload,
45+
- chip::NodeId nodeid)
46+
+ chip::NodeId nodeid, bool networkOnly)
47+
{
48+
+ chip::Controller::DiscoveryType discoveryType = chip::Controller::DiscoveryType::kAll;
49+
sPairingDelegate.SetExpectingPairingComplete(true);
50+
- return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters));
51+
+ if (networkOnly)
52+
+ discoveryType = chip::Controller::DiscoveryType::kDiscoveryNetworkOnly;
53+
+ return ToPyChipError(devCtrl->PairDevice(nodeid, onboardingPayload, sCommissioningParameters, discoveryType));
54+
}
55+
56+
namespace {
57+
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py
58+
index 8fa20dc752..72a1f7aaa6 100644
59+
--- a/src/controller/python/chip/ChipDeviceCtrl.py
60+
+++ b/src/controller/python/chip/ChipDeviceCtrl.py
61+
@@ -1580,7 +1580,7 @@ class ChipDeviceControllerBase():
62+
self._dmLib.pychip_DeviceController_ConnectIP.restype = PyChipError
63+
64+
self._dmLib.pychip_DeviceController_ConnectWithCode.argtypes = [
65+
- c_void_p, c_char_p, c_uint64]
66+
+ c_void_p, c_char_p, c_uint64, c_bool]
67+
self._dmLib.pychip_DeviceController_ConnectWithCode.restype = PyChipError
68+
69+
self._dmLib.pychip_DeviceController_UnpairDevice.argtypes = [
70+
@@ -1893,7 +1893,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
71+
return PyChipError(CHIP_ERROR_TIMEOUT)
72+
return self._ChipStack.commissioningEventRes
73+
74+
- def CommissionWithCode(self, setupPayload: str, nodeid: int) -> PyChipError:
75+
+ def CommissionWithCode(self, setupPayload: str, nodeid: int, networkOnly: bool = False) -> PyChipError:
76+
''' Commission with the given nodeid from the setupPayload.
77+
setupPayload may be a QR or manual code.
78+
'''
79+
@@ -1909,7 +1909,7 @@ class ChipDeviceController(ChipDeviceControllerBase):
80+
81+
self._ChipStack.CallAsync(
82+
lambda: self._dmLib.pychip_DeviceController_ConnectWithCode(
83+
- self.devCtrl, setupPayload, nodeid)
84+
+ self.devCtrl, setupPayload, nodeid, networkOnly)
85+
)
86+
if not self._ChipStack.commissioningCompleteEvent.isSet():
87+
# Error 50 is a timeout
88+
--
89+
2.43.0
90+

0 commit comments

Comments
 (0)