-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from home-assistant-libs/commission-with-code-…
…on-network-only Support commissioning with manual pairing code on network only
- Loading branch information
Showing
1 changed file
with
90 additions
and
0 deletions.
There are no files selected for viewing
90 changes: 90 additions & 0 deletions
90
0004-Python-Support-commissioning-with-code-on-network-on.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
From e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7 Mon Sep 17 00:00:00 2001 | ||
Message-ID: <e34fbf7b58908fa777335cbc4da4a0d6b26fe6d7.1703059244.git.stefan@agner.ch> | ||
From: Stefan Agner <stefan@agner.ch> | ||
Date: Thu, 14 Dec 2023 13:33:05 +0100 | ||
Subject: [PATCH] [Python] Support commissioning with code on network only | ||
(#31000) | ||
|
||
* [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 | ||
--- | ||
.../python/ChipDeviceController-ScriptBinding.cpp | 10 +++++++--- | ||
src/controller/python/chip/ChipDeviceCtrl.py | 6 +++--- | ||
2 files changed, 10 insertions(+), 6 deletions(-) | ||
|
||
diff --git a/src/controller/python/ChipDeviceController-ScriptBinding.cpp b/src/controller/python/ChipDeviceController-ScriptBinding.cpp | ||
index a7732a4836..c4b12570fd 100644 | ||
--- a/src/controller/python/ChipDeviceController-ScriptBinding.cpp | ||
+++ b/src/controller/python/ChipDeviceController-ScriptBinding.cpp | ||
@@ -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> | ||
@@ -135,7 +136,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); | ||
@@ -397,10 +398,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 { | ||
diff --git a/src/controller/python/chip/ChipDeviceCtrl.py b/src/controller/python/chip/ChipDeviceCtrl.py | ||
index 22ae11cda6..de6f1fff03 100644 | ||
--- a/src/controller/python/chip/ChipDeviceCtrl.py | ||
+++ b/src/controller/python/chip/ChipDeviceCtrl.py | ||
@@ -1422,7 +1422,7 @@ class ChipDeviceControllerBase(): | ||
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 = [ | ||
@@ -1726,7 +1726,7 @@ class ChipDeviceController(ChipDeviceControllerBase): | ||
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: | ||
self.CheckIsActive() | ||
|
||
setupPayload = setupPayload.encode() + b'\0' | ||
@@ -1739,7 +1739,7 @@ class ChipDeviceController(ChipDeviceControllerBase): | ||
|
||
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 | ||
-- | ||
2.43.0 | ||
|