@@ -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 )
@@ -365,7 +368,10 @@ def HandleCommissioningComplete(nodeId: int, err: PyChipError):
365
368
logging .exception ("HandleCommissioningComplete called unexpectedly" )
366
369
return
367
370
368
- self ._commissioning_complete_future .set_result (err )
371
+ if err .is_success :
372
+ self ._commissioning_complete_future .set_result (nodeId )
373
+ else :
374
+ self ._commissioning_complete_future .set_exception (err .to_exception ())
369
375
370
376
def HandleFabricCheck (nodeId ):
371
377
self .fabricCheckNodeId = nodeId
@@ -413,14 +419,17 @@ def HandlePASEEstablishmentComplete(err: PyChipError):
413
419
# During Commissioning, HandlePASEEstablishmentComplete will also be called.
414
420
# Only complete the future if PASE session establishment failed.
415
421
if not err .is_success :
416
- self ._commissioning_complete_future .set_result (err )
422
+ self ._commissioning_complete_future .set_exception (err . to_exception () )
417
423
return
418
424
419
425
if self ._pase_establishment_complete_future is None :
420
426
logging .exception ("HandlePASEEstablishmentComplete called unexpectedly" )
421
427
return
422
428
423
- self ._pase_establishment_complete_future .set_result (err )
429
+ if err .is_success :
430
+ self ._pase_establishment_complete_future .set_result (None )
431
+ else :
432
+ self ._pase_establishment_complete_future .set_exception (err .to_exception ())
424
433
425
434
self .pairingDelegate = pairingDelegate
426
435
self .devCtrl = devCtrl
@@ -538,7 +547,12 @@ def IsConnected(self):
538
547
self .devCtrl )
539
548
)
540
549
541
- def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> PyChipError :
550
+ def ConnectBLE (self , discriminator : int , setupPinCode : int , nodeid : int , isShortDiscriminator : bool = False ) -> int :
551
+ """Connect to a BLE device using the given discriminator and setup pin code.
552
+
553
+ Returns:
554
+ - Effective Node ID of the device (as defined by the assigned NOC)
555
+ """
542
556
self .CheckIsActive ()
543
557
544
558
self ._commissioning_complete_future = concurrent .futures .Future ()
@@ -550,11 +564,7 @@ def ConnectBLE(self, discriminator: int, setupPinCode: int, nodeid: int, isShort
550
564
self .devCtrl , discriminator , isShortDiscriminator , setupPinCode , nodeid )
551
565
).raise_on_error ()
552
566
553
- # TODO: Change return None. Only returning on success is not useful.
554
- # but that is what the previous implementation did.
555
- res = self ._commissioning_complete_future .result ()
556
- res .raise_on_error ()
557
- return res
567
+ return self ._commissioning_complete_future .result ()
558
568
finally :
559
569
self ._commissioning_complete_future = None
560
570
@@ -600,7 +610,7 @@ def CloseSession(self, nodeid):
600
610
self .devCtrl , nodeid )
601
611
).raise_on_error ()
602
612
603
- def EstablishPASESessionBLE (self , setupPinCode : int , discriminator : int , nodeid : int ):
613
+ def EstablishPASESessionBLE (self , setupPinCode : int , discriminator : int , nodeid : int ) -> None :
604
614
self .CheckIsActive ()
605
615
606
616
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -611,16 +621,11 @@ def EstablishPASESessionBLE(self, setupPinCode: int, discriminator: int, nodeid:
611
621
self .devCtrl , setupPinCode , discriminator , nodeid )
612
622
).raise_on_error ()
613
623
614
- # TODO: This is a bit funky, but what the API returned with the previous
615
- # implementation. We should revisit this.
616
- err = self ._pase_establishment_complete_future .result ()
617
- if not err .is_success :
618
- return err .to_exception ()
619
- return None
624
+ self ._pase_establishment_complete_future .result ()
620
625
finally :
621
626
self ._pase_establishment_complete_future = None
622
627
623
- def EstablishPASESessionIP (self , ipaddr : str , setupPinCode : int , nodeid : int , port : int = 0 ):
628
+ def EstablishPASESessionIP (self , ipaddr : str , setupPinCode : int , nodeid : int , port : int = 0 ) -> None :
624
629
self .CheckIsActive ()
625
630
626
631
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -631,16 +636,11 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
631
636
self .devCtrl , ipaddr .encode ("utf-8" ), setupPinCode , nodeid , port )
632
637
).raise_on_error ()
633
638
634
- # TODO: This is a bit funky, but what the API returned with the previous
635
- # implementation. We should revisit this.
636
- err = self ._pase_establishment_complete_future .result ()
637
- if not err .is_success :
638
- return err .to_exception ()
639
- return None
639
+ self ._pase_establishment_complete_future .result ()
640
640
finally :
641
641
self ._pase_establishment_complete_future = None
642
642
643
- def EstablishPASESession (self , setUpCode : str , nodeid : int ):
643
+ def EstablishPASESession (self , setUpCode : str , nodeid : int ) -> None :
644
644
self .CheckIsActive ()
645
645
646
646
self ._pase_establishment_complete_future = concurrent .futures .Future ()
@@ -651,12 +651,7 @@ def EstablishPASESession(self, setUpCode: str, nodeid: int):
651
651
self .devCtrl , setUpCode .encode ("utf-8" ), nodeid )
652
652
).raise_on_error ()
653
653
654
- # TODO: This is a bit funky, but what the API returned with the previous
655
- # implementation. We should revisit this.
656
- err = self ._pase_establishment_complete_future .result ()
657
- if not err .is_success :
658
- return err .to_exception ()
659
- return None
654
+ self ._pase_establishment_complete_future .result ()
660
655
finally :
661
656
self ._pase_establishment_complete_future = None
662
657
@@ -1874,17 +1869,19 @@ def caIndex(self) -> int:
1874
1869
def fabricAdmin (self ) -> FabricAdmin :
1875
1870
return self ._fabricAdmin
1876
1871
1877
- def Commission (self , nodeid ) -> PyChipError :
1872
+ def Commission (self , nodeid ) -> int :
1878
1873
'''
1879
1874
Start the auto-commissioning process on a node after establishing a PASE connection.
1880
1875
This function is intended to be used in conjunction with `EstablishPASESessionBLE` or
1881
1876
`EstablishPASESessionIP`. It can be called either before or after the DevicePairingDelegate
1882
1877
receives the OnPairingComplete call. Commissioners that want to perform simple
1883
- auto-commissioning should use the supplied "PairDevice" functions above , which will
1878
+ auto-commissioning should use the supplied "CommissionWithCode" function , which will
1884
1879
establish the PASE connection and commission automatically.
1885
1880
1886
- Return:
1887
- bool: True if successful, False otherwise.
1881
+ Raises a ChipStackError on failure.
1882
+
1883
+ Returns:
1884
+ - Effective Node ID of the device (as defined by the assigned NOC)
1888
1885
'''
1889
1886
self .CheckIsActive ()
1890
1887
@@ -1900,13 +1897,13 @@ def Commission(self, nodeid) -> PyChipError:
1900
1897
finally :
1901
1898
self ._commissioning_complete_future = None
1902
1899
1903
- def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> PyChipError :
1900
+ def CommissionThread (self , discriminator , setupPinCode , nodeId , threadOperationalDataset : bytes , isShortDiscriminator : bool = False ) -> int :
1904
1901
''' Commissions a Thread device over BLE
1905
1902
'''
1906
1903
self .SetThreadOperationalDataset (threadOperationalDataset )
1907
1904
return self .ConnectBLE (discriminator , setupPinCode , nodeId , isShortDiscriminator )
1908
1905
1909
- def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> PyChipError :
1906
+ def CommissionWiFi (self , discriminator , setupPinCode , nodeId , ssid : str , credentials : str , isShortDiscriminator : bool = False ) -> int :
1910
1907
''' Commissions a Wi-Fi device over BLE.
1911
1908
'''
1912
1909
self .SetWiFiCredentials (ssid , credentials )
@@ -2009,7 +2006,7 @@ def GetFabricCheckResult(self) -> int:
2009
2006
return self .fabricCheckNodeId
2010
2007
2011
2008
def CommissionOnNetwork (self , nodeId : int , setupPinCode : int ,
2012
- filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> PyChipError :
2009
+ filterType : DiscoveryFilterType = DiscoveryFilterType .NONE , filter : typing .Any = None , discoveryTimeoutMsec : int = 30000 ) -> int :
2013
2010
'''
2014
2011
Does the routine for OnNetworkCommissioning, with a filter for mDNS discovery.
2015
2012
Supported filters are:
@@ -2025,6 +2022,11 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2025
2022
DiscoveryFilterType.COMPRESSED_FABRIC_ID
2026
2023
2027
2024
The filter can be an integer, a string or None depending on the actual type of selected filter.
2025
+
2026
+ Raises a ChipStackError on failure.
2027
+
2028
+ Returns:
2029
+ - Effective Node ID of the device (as defined by the assigned NOC)
2028
2030
'''
2029
2031
self .CheckIsActive ()
2030
2032
@@ -2044,9 +2046,14 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2044
2046
finally :
2045
2047
self ._commissioning_complete_future = None
2046
2048
2047
- def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> PyChipError :
2049
+ def CommissionWithCode (self , setupPayload : str , nodeid : int , discoveryType : DiscoveryType = DiscoveryType .DISCOVERY_ALL ) -> int :
2048
2050
''' Commission with the given nodeid from the setupPayload.
2049
2051
setupPayload may be a QR or manual code.
2052
+
2053
+ Raises a ChipStackError on failure.
2054
+
2055
+ Returns:
2056
+ - Effective Node ID of the device (as defined by the assigned NOC)
2050
2057
'''
2051
2058
self .CheckIsActive ()
2052
2059
@@ -2063,8 +2070,14 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
2063
2070
finally :
2064
2071
self ._commissioning_complete_future = None
2065
2072
2066
- def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> PyChipError :
2067
- """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode` """
2073
+ def CommissionIP (self , ipaddr : str , setupPinCode : int , nodeid : int ) -> int :
2074
+ """ DEPRECATED, DO NOT USE! Use `CommissionOnNetwork` or `CommissionWithCode`
2075
+
2076
+ Raises a ChipStackError on failure.
2077
+
2078
+ Returns:
2079
+ - Effective Node ID of the device (as defined by the assigned NOC)
2080
+ """
2068
2081
self .CheckIsActive ()
2069
2082
2070
2083
self ._commissioning_complete_future = concurrent .futures .Future ()
0 commit comments