@@ -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,14 +414,17 @@ 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 :
415
421
logging .exception ("HandlePASEEstablishmentComplete called unexpectedly" )
416
422
return
417
423
418
- self ._pase_establishment_complete_future .set_result (err )
424
+ if err .is_success :
425
+ self ._pase_establishment_complete_future .set_result (None )
426
+ else :
427
+ self ._pase_establishment_complete_future .set_exception (err .to_exception ())
419
428
420
429
self .pairingDelegate = pairingDelegate
421
430
self .devCtrl = devCtrl
@@ -533,7 +542,12 @@ def IsConnected(self):
533
542
self .devCtrl )
534
543
)
535
544
536
- def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> PyChipError :
545
+ def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> int :
546
+ """Connect to a BLE device using the given discriminator and setup pin code.
547
+
548
+ Returns:
549
+ - Effective Node ID of the device (as defined by the assigned NOC)
550
+ """
537
551
self .CheckIsActive ()
538
552
539
553
self ._commissioning_complete_future = concurrent .futures .Future ()
@@ -545,11 +559,7 @@ def ConnectBLE(self, discriminator: int, setupPinCode: int, nodeid: int, isShort
545
559
self .devCtrl , discriminator , isShortDiscriminator , setupPinCode , nodeid )
546
560
).raise_on_error ()
547
561
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
562
+ return self ._commissioning_complete_future .result ()
553
563
finally :
554
564
self ._commissioning_complete_future = None
555
565
@@ -595,7 +605,7 @@ def CloseSession(self, nodeid):
595
605
self .devCtrl , nodeid )
596
606
).raise_on_error ()
597
607
598
- def EstablishPASESessionBLE (self , setupPinCode : int , discriminator : int , nodeid : int ):
608
+ def EstablishPASESessionBLE (self , setupPinCode : int , discriminator : int , nodeid : int ) -> None :
599
609
self .CheckIsActive ()
600
610
601
611
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -606,16 +616,11 @@ def EstablishPASESessionBLE(self, setupPinCode: int, discriminator: int, nodeid:
606
616
self .devCtrl , setupPinCode , discriminator , nodeid )
607
617
).raise_on_error ()
608
618
609
- # TODO: This is a bit funky, but what the API returned with the previous
610
- # implementation. We should revisit this.
611
- err = self ._pase_establishment_complete_future .result ()
612
- if not err .is_success :
613
- return err .to_exception ()
614
- return None
619
+ self ._pase_establishment_complete_future .result ()
615
620
finally :
616
621
self ._pase_establishment_complete_future = None
617
622
618
- def EstablishPASESessionIP (self , ipaddr : str , setupPinCode : int , nodeid : int , port : int = 0 ):
623
+ def EstablishPASESessionIP (self , ipaddr : str , setupPinCode : int , nodeid : int , port : int = 0 ) -> None :
619
624
self .CheckIsActive ()
620
625
621
626
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -626,16 +631,11 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
626
631
self .devCtrl , ipaddr .encode ("utf-8" ), setupPinCode , nodeid , port )
627
632
).raise_on_error ()
628
633
629
- # TODO: This is a bit funky, but what the API returned with the previous
630
- # implementation. We should revisit this.
631
- err = self ._pase_establishment_complete_future .result ()
632
- if not err .is_success :
633
- return err .to_exception ()
634
- return None
634
+ self ._pase_establishment_complete_future .result ()
635
635
finally :
636
636
self ._pase_establishment_complete_future = None
637
637
638
- def EstablishPASESession (self , setUpCode : str , nodeid : int ):
638
+ def EstablishPASESession (self , setUpCode : str , nodeid : int ) -> None :
639
639
self .CheckIsActive ()
640
640
641
641
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -646,12 +646,7 @@ def EstablishPASESession(self, setUpCode: str, nodeid: int):
646
646
self .devCtrl , setUpCode .encode ("utf-8" ), nodeid )
647
647
).raise_on_error ()
648
648
649
- # TODO: This is a bit funky, but what the API returned with the previous
650
- # implementation. We should revisit this.
651
- err = self ._pase_establishment_complete_future .result ()
652
- if not err .is_success :
653
- return err .to_exception ()
654
- return None
649
+ self ._pase_establishment_complete_future .result ()
655
650
finally :
656
651
self ._pase_establishment_complete_future = None
657
652
@@ -1853,17 +1848,19 @@ def caIndex(self) -> int:
1853
1848
def fabricAdmin (self ) -> FabricAdmin :
1854
1849
return self ._fabricAdmin
1855
1850
1856
- def Commission (self , nodeid ) -> PyChipError :
1851
+ def Commission (self , nodeid ) -> int :
1857
1852
'''
1858
1853
Start the auto-commissioning process on a node after establishing a PASE connection.
1859
1854
This function is intended to be used in conjunction with `EstablishPASESessionBLE` or
1860
1855
`EstablishPASESessionIP`. It can be called either before or after the DevicePairingDelegate
1861
1856
receives the OnPairingComplete call. Commissioners that want to perform simple
1862
- auto-commissioning should use the supplied "PairDevice" functions above , which will
1857
+ auto-commissioning should use the supplied "CommissionWithCode" function , which will
1863
1858
establish the PASE connection and commission automatically.
1864
1859
1865
- Return:
1866
- bool: True if successful, False otherwise.
1860
+ Raises a ChipStackError on failure.
1861
+
1862
+ Returns:
1863
+ - Effective Node ID of the device (as defined by the assigned NOC)
1867
1864
'''
1868
1865
self .CheckIsActive ()
1869
1866
@@ -1879,13 +1876,13 @@ def Commission(self, nodeid) -> PyChipError:
1879
1876
finally :
1880
1877
self ._commissioning_complete_future = None
1881
1878
1882
- def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> PyChipError :
1879
+ def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> int :
1883
1880
''' Commissions a Thread device over BLE
1884
1881
'''
1885
1882
self .SetThreadOperationalDataset (threadOperationalDataset )
1886
1883
return self .ConnectBLE (discriminator , setupPinCode , nodeId , isShortDiscriminator )
1887
1884
1888
- def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> PyChipError :
1885
+ def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> int :
1889
1886
''' Commissions a Wi-Fi device over BLE.
1890
1887
'''
1891
1888
self .SetWiFiCredentials (ssid , credentials )
@@ -1988,7 +1985,7 @@ def GetFabricCheckResult(self) -> int:
1988
1985
return self .fabricCheckNodeId
1989
1986
1990
1987
def CommissionOnNetwork (self , nodeId : int , setupPinCode : int ,
1991
- filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> PyChipError :
1988
+ filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> int :
1992
1989
'''
1993
1990
Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery.
1994
1991
Supported filters are:
@@ -2004,6 +2001,11 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2004
2001
DiscoveryFilterType.COMPRESSED_FABRIC_ID
2005
2002
2006
2003
The filter can be an integer, a string or None depending on the actual type of selected filter.
2004
+
2005
+ Raises a ChipStackError on failure.
2006
+
2007
+ Returns:
2008
+ - Effective Node ID of the device (as defined by the assigned NOC)
2007
2009
'''
2008
2010
self .CheckIsActive ()
2009
2011
@@ -2023,9 +2025,14 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2023
2025
finally :
2024
2026
self ._commissioning_complete_future = None
2025
2027
2026
- def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> PyChipError :
2028
+ def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> int :
2027
2029
''' Commission with the given nodeid from the setupPayload.
2028
2030
setupPayload may be a QR or manual code.
2031
+
2032
+ Raises a ChipStackError on failure.
2033
+
2034
+ Returns:
2035
+ - Effective Node ID of the device (as defined by the assigned NOC)
2029
2036
'''
2030
2037
self .CheckIsActive ()
2031
2038
@@ -2042,8 +2049,14 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
2042
2049
finally :
2043
2050
self ._commissioning_complete_future = None
2044
2051
2045
- def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> PyChipError :
2046
- """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode` """
2052
+ def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> int :
2053
+ """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode`
2054
+
2055
+ Raises a ChipStackError on failure.
2056
+
2057
+ Returns:
2058
+ - Effective Node ID of the device (as defined by the assigned NOC)
2059
+ """
2047
2060
self .CheckIsActive ()
2048
2061
2049
2062
self ._commissioning_complete_future = concurrent .futures .Future ()
0 commit comments