@@ -230,11 +230,14 @@ class CommissionableNode(discovery.CommissionableNode):
230
230
def SetDeviceController (self , devCtrl : 'ChipDeviceController' ):
231
231
self ._devCtrl = devCtrl
232
232
233
- def Commission (self , nodeId : int , setupPinCode : int ) -> PyChipError :
233
+ def Commission (self , nodeId : int , setupPinCode : int ) -> int :
234
234
''' Commission the device using the device controller discovered this device.
235
235
236
236
nodeId: The nodeId commissioned to the device
237
237
setupPinCode: The setup pin code of the device
238
+
239
+ Returns:
240
+ - Effective Node ID of the device (as defined by the assigned NOC)
238
241
'''
239
242
return self ._devCtrl .CommissionOnNetwork (
240
243
nodeId , setupPinCode , filterType = discovery .FilterType .INSTANCE_NAME , filter = self .instanceName )
@@ -360,7 +363,10 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError):
360
363
logging .exception ("HandleCommissioningComplete called unexpectedly" )
361
364
return
362
365
363
- self ._commissioning_complete_future .set_result (err )
366
+ if err .is_success :
367
+ self ._commissioning_complete_future .set_result (nodeId )
368
+ else :
369
+ self ._commissioning_complete_future .set_exception (err .to_exception ())
364
370
365
371
def HandleFabricCheck (nodeId ):
366
372
self .fabricCheckNodeId = nodeId
@@ -408,7 +414,7 @@ def HandlePASEEstablishmentComplete(err: PyChipError):
408
414
# During Commissioning, HandlePASEEstablishmentComplete will also be called.
409
415
# Only complete the future if PASE session establishment failed.
410
416
if not err .is_success :
411
- self ._commissioning_complete_future .set_result (err )
417
+ self ._commissioning_complete_future .set_exception (err . to_exception () )
412
418
return
413
419
414
420
if self ._pase_establishment_complete_future is None :
@@ -533,7 +539,12 @@ def IsConnected(self):
533
539
self .devCtrl )
534
540
)
535
541
536
- def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> PyChipError :
542
+ def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> int :
543
+ """Connect to a BLE device using the given discriminator and setup pin code.
544
+
545
+ Returns:
546
+ - Effective Node ID of the device (as defined by the assigned NOC)
547
+ """
537
548
self .CheckIsActive ()
538
549
539
550
self ._commissioning_complete_future = concurrent .futures .Future ()
@@ -545,11 +556,7 @@ def ConnectBLE(self, discriminator: int, setupPinCode: int, nodeid: int, isShort
545
556
self .devCtrl , discriminator , isShortDiscriminator , setupPinCode , nodeid )
546
557
).raise_on_error ()
547
558
548
- # TODO: Change return None. Only returning on success is not useful.
549
- # but that is what the previous implementation did.
550
- res = self ._commissioning_complete_future .result ()
551
- res .raise_on_error ()
552
- return res
559
+ return self ._commissioning_complete_future .result ()
553
560
finally :
554
561
self ._commissioning_complete_future = None
555
562
@@ -1853,17 +1860,19 @@ def caIndex(self) -> int:
1853
1860
def fabricAdmin (self ) -> FabricAdmin :
1854
1861
return self ._fabricAdmin
1855
1862
1856
- def Commission (self , nodeid ) -> PyChipError :
1863
+ def Commission (self , nodeid ) -> int :
1857
1864
'''
1858
1865
Start the auto-commissioning process on a node after establishing a PASE connection.
1859
1866
This function is intended to be used in conjunction with `EstablishPASESessionBLE` or
1860
1867
`EstablishPASESessionIP`. It can be called either before or after the DevicePairingDelegate
1861
1868
receives the OnPairingComplete call. Commissioners that want to perform simple
1862
- auto-commissioning should use the supplied "PairDevice" functions above , which will
1869
+ auto-commissioning should use the supplied "CommissionWithCode" function , which will
1863
1870
establish the PASE connection and commission automatically.
1864
1871
1865
- Return:
1866
- bool: True if successful, False otherwise.
1872
+ Raises a ChipStackError on failure.
1873
+
1874
+ Returns:
1875
+ - Effective Node ID of the device (as defined by the assigned NOC)
1867
1876
'''
1868
1877
self .CheckIsActive ()
1869
1878
@@ -1879,13 +1888,13 @@ def Commission(self, nodeid) -> PyChipError:
1879
1888
finally :
1880
1889
self ._commissioning_complete_future = None
1881
1890
1882
- def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> PyChipError :
1891
+ def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> int :
1883
1892
''' Commissions a Thread device over BLE
1884
1893
'''
1885
1894
self .SetThreadOperationalDataset (threadOperationalDataset )
1886
1895
return self .ConnectBLE (discriminator , setupPinCode , nodeId , isShortDiscriminator )
1887
1896
1888
- def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> PyChipError :
1897
+ def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> int :
1889
1898
''' Commissions a Wi-Fi device over BLE.
1890
1899
'''
1891
1900
self .SetWiFiCredentials (ssid , credentials )
@@ -1988,7 +1997,7 @@ def GetFabricCheckResult(self) -> int:
1988
1997
return self .fabricCheckNodeId
1989
1998
1990
1999
def CommissionOnNetwork (self , nodeId : int , setupPinCode : int ,
1991
- filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> PyChipError :
2000
+ filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> int :
1992
2001
'''
1993
2002
Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery.
1994
2003
Supported filters are:
@@ -2004,6 +2013,11 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2004
2013
DiscoveryFilterType.COMPRESSED_FABRIC_ID
2005
2014
2006
2015
The filter can be an integer, a string or None depending on the actual type of selected filter.
2016
+
2017
+ Raises a ChipStackError on failure.
2018
+
2019
+ Returns:
2020
+ - Effective Node ID of the device (as defined by the assigned NOC)
2007
2021
'''
2008
2022
self .CheckIsActive ()
2009
2023
@@ -2023,9 +2037,14 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2023
2037
finally :
2024
2038
self ._commissioning_complete_future = None
2025
2039
2026
- def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> PyChipError :
2040
+ def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> int :
2027
2041
''' Commission with the given nodeid from the setupPayload.
2028
2042
setupPayload may be a QR or manual code.
2043
+
2044
+ Raises a ChipStackError on failure.
2045
+
2046
+ Returns:
2047
+ - Effective Node ID of the device (as defined by the assigned NOC)
2029
2048
'''
2030
2049
self .CheckIsActive ()
2031
2050
@@ -2042,8 +2061,14 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
2042
2061
finally :
2043
2062
self ._commissioning_complete_future = None
2044
2063
2045
- def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> PyChipError :
2046
- """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode` """
2064
+ def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> int :
2065
+ """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode`
2066
+
2067
+ Raises a ChipStackError on failure.
2068
+
2069
+ Returns:
2070
+ - Effective Node ID of the device (as defined by the assigned NOC)
2071
+ """
2047
2072
self .CheckIsActive ()
2048
2073
2049
2074
self ._commissioning_complete_future = concurrent .futures .Future ()
0 commit comments