@@ -253,8 +253,10 @@ def __init__(self, name: str = ''):
253
253
254
254
self ._InitLib ()
255
255
256
+ pairingDelegate = c_void_p (None )
256
257
devCtrl = c_void_p (None )
257
258
259
+ self .pairingDelegate = pairingDelegate
258
260
self .devCtrl = devCtrl
259
261
self .name = name
260
262
self .fabricCheckNodeId = - 1
@@ -263,7 +265,7 @@ def __init__(self, name: str = ''):
263
265
self ._Cluster = ChipClusters (builtins .chipStack )
264
266
self ._Cluster .InitLib (self ._dmLib )
265
267
266
- def _set_dev_ctrl (self , devCtrl ):
268
+ def _set_dev_ctrl (self , devCtrl , pairingDelegate ):
267
269
def HandleCommissioningComplete (nodeid , err ):
268
270
if err .is_success :
269
271
logging .info ("Commissioning complete" )
@@ -321,25 +323,26 @@ def HandlePASEEstablishmentComplete(err: PyChipError):
321
323
if not err .is_success :
322
324
HandleCommissioningComplete (0 , err )
323
325
326
+ self .pairingDelegate = pairingDelegate
324
327
self .devCtrl = devCtrl
325
328
326
329
self .cbHandlePASEEstablishmentCompleteFunct = _DevicePairingDelegate_OnPairingCompleteFunct (
327
330
HandlePASEEstablishmentComplete )
328
331
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetKeyExchangeCallback (
329
- self .devCtrl , self .cbHandlePASEEstablishmentCompleteFunct )
332
+ self .pairingDelegate , self .cbHandlePASEEstablishmentCompleteFunct )
330
333
331
334
self .cbHandleCommissioningCompleteFunct = _DevicePairingDelegate_OnCommissioningCompleteFunct (
332
335
HandleCommissioningComplete )
333
336
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetCommissioningCompleteCallback (
334
- self .devCtrl , self .cbHandleCommissioningCompleteFunct )
337
+ self .pairingDelegate , self .cbHandleCommissioningCompleteFunct )
335
338
336
339
self .cbHandleFabricCheckFunct = _DevicePairingDelegate_OnFabricCheckFunct (HandleFabricCheck )
337
- self ._dmLib .pychip_ScriptDevicePairingDelegate_SetFabricCheckCallback (self .cbHandleFabricCheckFunct )
340
+ self ._dmLib .pychip_ScriptDevicePairingDelegate_SetFabricCheckCallback (self .pairingDelegate , self . cbHandleFabricCheckFunct )
338
341
339
342
self .cbHandleOpenWindowCompleteFunct = _DevicePairingDelegate_OnOpenWindowCompleteFunct (
340
343
HandleOpenWindowComplete )
341
344
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetOpenWindowCompleteCallback (
342
- self .devCtrl , self .cbHandleOpenWindowCompleteFunct )
345
+ self .pairingDelegate , self .cbHandleOpenWindowCompleteFunct )
343
346
344
347
self .cbHandleDeviceUnpairCompleteFunct = _DeviceUnpairingCompleteFunct (HandleUnpairDeviceComplete )
345
348
@@ -355,6 +358,11 @@ def _finish_init(self):
355
358
356
359
ChipDeviceController .activeList .add (self )
357
360
361
+ def _enablePairingCompeleteCallback (self , value : bool ):
362
+ self ._ChipStack .Call (
363
+ lambda : self ._dmLib .pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete (self .pairingDelegate , value )
364
+ ).raise_on_error ()
365
+
358
366
@property
359
367
def fabricAdmin (self ) -> FabricAdmin .FabricAdmin :
360
368
return self ._fabricAdmin
@@ -389,8 +397,9 @@ def Shutdown(self):
389
397
if self .devCtrl is not None :
390
398
self ._ChipStack .Call (
391
399
lambda : self ._dmLib .pychip_DeviceController_DeleteDeviceController (
392
- self .devCtrl )
400
+ self .devCtrl , self . pairingDelegate )
393
401
).raise_on_error ()
402
+ self .pairingDelegate = None
394
403
self .devCtrl = None
395
404
396
405
ChipDeviceController .activeList .remove (self )
@@ -437,6 +446,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid) -> PyChipError:
437
446
self ._ChipStack .commissioningCompleteEvent .clear ()
438
447
439
448
self .state = DCState .COMMISSIONING
449
+ self ._enablePairingCompeleteCallback (True )
440
450
self ._ChipStack .CallAsync (
441
451
lambda : self ._dmLib .pychip_DeviceController_ConnectBLE (
442
452
self .devCtrl , discriminator , setupPinCode , nodeid )
@@ -487,6 +497,7 @@ def EstablishPASESessionBLE(self, setupPinCode: int, discriminator: int, nodeid:
487
497
self .CheckIsActive ()
488
498
489
499
self .state = DCState .RENDEZVOUS_ONGOING
500
+ self ._enablePairingCompeleteCallback (True )
490
501
return self ._ChipStack .CallAsync (
491
502
lambda : self ._dmLib .pychip_DeviceController_EstablishPASESessionBLE (
492
503
self .devCtrl , setupPinCode , discriminator , nodeid )
@@ -496,6 +507,7 @@ def EstablishPASESessionIP(self, ipaddr: str, setupPinCode: int, nodeid: int, po
496
507
self .CheckIsActive ()
497
508
498
509
self .state = DCState .RENDEZVOUS_ONGOING
510
+ self ._enablePairingCompeleteCallback (True )
499
511
return self ._ChipStack .CallAsync (
500
512
lambda : self ._dmLib .pychip_DeviceController_EstablishPASESessionIP (
501
513
self .devCtrl , ipaddr .encode ("utf-8" ), setupPinCode , nodeid , port )
@@ -505,6 +517,7 @@ def EstablishPASESession(self, setUpCode: str, nodeid: int):
505
517
self .CheckIsActive ()
506
518
507
519
self .state = DCState .RENDEZVOUS_ONGOING
520
+ self ._enablePairingCompeleteCallback (True )
508
521
return self ._ChipStack .CallAsync (
509
522
lambda : self ._dmLib .pychip_DeviceController_EstablishPASESession (
510
523
self .devCtrl , setUpCode .encode ("utf-8" ), nodeid )
@@ -726,7 +739,7 @@ def OpenCommissioningWindow(self, nodeid: int, timeout: int, iteration: int,
726
739
self .CheckIsActive ()
727
740
self ._ChipStack .CallAsync (
728
741
lambda : self ._dmLib .pychip_DeviceController_OpenCommissioningWindow (
729
- self .devCtrl , nodeid , timeout , iteration , discriminator , option )
742
+ self .devCtrl , self . pairingDelegate , nodeid , timeout , iteration , discriminator , option )
730
743
).raise_on_error ()
731
744
self ._ChipStack .callbackRes .raise_on_error ()
732
745
return self ._ChipStack .openCommissioningWindowPincode [nodeid ]
@@ -1515,16 +1528,13 @@ def _InitLib(self):
1515
1528
self ._dmLib = CDLL (self ._ChipStack .LocateChipDLL ())
1516
1529
1517
1530
self ._dmLib .pychip_DeviceController_DeleteDeviceController .argtypes = [
1518
- c_void_p ]
1531
+ c_void_p , c_void_p ]
1519
1532
self ._dmLib .pychip_DeviceController_DeleteDeviceController .restype = PyChipError
1520
1533
1521
1534
self ._dmLib .pychip_DeviceController_ConnectBLE .argtypes = [
1522
1535
c_void_p , c_uint16 , c_uint32 , c_uint64 ]
1523
1536
self ._dmLib .pychip_DeviceController_ConnectBLE .restype = PyChipError
1524
1537
1525
- self ._dmLib .pychip_DeviceController_ConnectIP .argtypes = [
1526
- c_void_p , c_char_p , c_uint32 , c_uint64 ]
1527
-
1528
1538
self ._dmLib .pychip_DeviceController_SetThreadOperationalDataset .argtypes = [
1529
1539
c_char_p , c_uint32 ]
1530
1540
self ._dmLib .pychip_DeviceController_SetThreadOperationalDataset .restype = PyChipError
@@ -1560,7 +1570,7 @@ def _InitLib(self):
1560
1570
self ._dmLib .pychip_DeviceController_Commission .restype = PyChipError
1561
1571
1562
1572
self ._dmLib .pychip_DeviceController_OnNetworkCommission .argtypes = [
1563
- c_void_p , c_uint64 , c_uint32 , c_uint8 , c_char_p , c_uint32 ]
1573
+ c_void_p , c_void_p , c_uint64 , c_uint32 , c_uint8 , c_char_p , c_uint32 ]
1564
1574
self ._dmLib .pychip_DeviceController_OnNetworkCommission .restype = PyChipError
1565
1575
1566
1576
self ._dmLib .pychip_DeviceController_DiscoverCommissionableNodes .argtypes = [
@@ -1598,17 +1608,20 @@ def _InitLib(self):
1598
1608
self ._dmLib .pychip_DeviceController_EstablishPASESessionBLE .argtypes = [
1599
1609
c_void_p , c_uint32 , c_uint16 , c_uint64 ]
1600
1610
self ._dmLib .pychip_DeviceController_EstablishPASESessionBLE .restype = PyChipError
1611
+
1601
1612
self ._dmLib .pychip_DeviceController_EstablishPASESession .argtypes = [
1602
1613
c_void_p , c_char_p , c_uint64 ]
1603
1614
self ._dmLib .pychip_DeviceController_EstablishPASESession .restype = PyChipError
1604
1615
1605
1616
self ._dmLib .pychip_DeviceController_DiscoverAllCommissionableNodes .argtypes = [
1606
1617
c_void_p ]
1607
1618
self ._dmLib .pychip_DeviceController_DiscoverAllCommissionableNodes .restype = PyChipError
1619
+
1608
1620
self ._dmLib .pychip_DeviceController_PrintDiscoveredDevices .argtypes = [
1609
1621
c_void_p ]
1610
1622
self ._dmLib .pychip_DeviceController_PrintDiscoveredDevices .argtypes = [
1611
1623
c_void_p , _ChipDeviceController_IterateDiscoveredCommissionableNodesFunct ]
1624
+
1612
1625
self ._dmLib .pychip_DeviceController_HasDiscoveredCommissionableNode .argtypes = [c_void_p ]
1613
1626
self ._dmLib .pychip_DeviceController_HasDiscoveredCommissionableNode .restype = c_bool
1614
1627
@@ -1653,9 +1666,13 @@ def _InitLib(self):
1653
1666
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetCommissioningStatusUpdateCallback .restype = PyChipError
1654
1667
1655
1668
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetFabricCheckCallback .argtypes = [
1656
- _DevicePairingDelegate_OnFabricCheckFunct ]
1669
+ c_void_p , _DevicePairingDelegate_OnFabricCheckFunct ]
1657
1670
self ._dmLib .pychip_ScriptDevicePairingDelegate_SetFabricCheckCallback .restype = PyChipError
1658
1671
1672
+ self ._dmLib .pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete .argtypes = [
1673
+ c_void_p , c_bool ]
1674
+ self ._dmLib .pychip_ScriptDevicePairingDelegate_SetExpectingPairingComplete .restype = PyChipError
1675
+
1659
1676
self ._dmLib .pychip_GetConnectedDeviceByNodeId .argtypes = [
1660
1677
c_void_p , c_uint64 , py_object , _DeviceAvailableCallbackFunct ]
1661
1678
self ._dmLib .pychip_GetConnectedDeviceByNodeId .restype = PyChipError
@@ -1683,8 +1700,9 @@ def _InitLib(self):
1683
1700
self ._dmLib .pychip_DeviceController_GetCompressedFabricId .restype = PyChipError
1684
1701
1685
1702
self ._dmLib .pychip_DeviceController_OpenCommissioningWindow .argtypes = [
1686
- c_void_p , c_uint64 , c_uint16 , c_uint32 , c_uint16 , c_uint8 ]
1703
+ c_void_p , c_void_p , c_uint64 , c_uint16 , c_uint32 , c_uint16 , c_uint8 ]
1687
1704
self ._dmLib .pychip_DeviceController_OpenCommissioningWindow .restype = PyChipError
1705
+
1688
1706
self ._dmLib .pychip_TestCommissionerUsed .argtypes = []
1689
1707
self ._dmLib .pychip_TestCommissionerUsed .restype = c_bool
1690
1708
@@ -1700,6 +1718,7 @@ def _InitLib(self):
1700
1718
self ._dmLib .pychip_SetTestCommissionerSimulateFailureOnStage .argtypes = [
1701
1719
c_uint8 ]
1702
1720
self ._dmLib .pychip_SetTestCommissionerSimulateFailureOnStage .restype = c_bool
1721
+
1703
1722
self ._dmLib .pychip_SetTestCommissionerSimulateFailureOnReport .argtypes = [
1704
1723
c_uint8 ]
1705
1724
self ._dmLib .pychip_SetTestCommissionerSimulateFailureOnReport .restype = c_bool
@@ -1712,8 +1731,7 @@ def _InitLib(self):
1712
1731
self ._dmLib .pychip_GetCompletionError .restype = PyChipError
1713
1732
1714
1733
self ._dmLib .pychip_DeviceController_IssueNOCChain .argtypes = [
1715
- c_void_p , py_object , c_char_p , c_size_t , c_uint64
1716
- ]
1734
+ c_void_p , py_object , c_char_p , c_size_t , c_uint64 ]
1717
1735
self ._dmLib .pychip_DeviceController_IssueNOCChain .restype = PyChipError
1718
1736
1719
1737
self ._dmLib .pychip_OpCreds_InitGroupTestingData .argtypes = [
@@ -1734,11 +1752,11 @@ def _InitLib(self):
1734
1752
self ._dmLib .pychip_DeviceController_GetLogFilter = c_uint8
1735
1753
1736
1754
self ._dmLib .pychip_OpCreds_AllocateController .argtypes = [c_void_p , POINTER (
1737
- c_void_p ), c_uint64 , c_uint64 , c_uint16 , c_char_p , c_bool , c_bool , POINTER (c_uint32 ), c_uint32 , c_void_p ]
1755
+ c_void_p ), POINTER ( c_void_p ), c_uint64 , c_uint64 , c_uint16 , c_char_p , c_bool , c_bool , POINTER (c_uint32 ), c_uint32 , c_void_p ]
1738
1756
self ._dmLib .pychip_OpCreds_AllocateController .restype = PyChipError
1739
1757
1740
1758
self ._dmLib .pychip_OpCreds_AllocateControllerForPythonCommissioningFLow .argtypes = [
1741
- POINTER (c_void_p ), c_void_p , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , c_uint16 , c_bool ]
1759
+ POINTER (c_void_p ), POINTER ( c_void_p ), c_void_p , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , POINTER (c_char ), c_uint32 , c_uint16 , c_bool ]
1742
1760
self ._dmLib .pychip_OpCreds_AllocateControllerForPythonCommissioningFLow .restype = PyChipError
1743
1761
1744
1762
self ._dmLib .pychip_DeviceController_SetIpk .argtypes = [c_void_p , POINTER (c_char ), c_size_t ]
@@ -1760,6 +1778,7 @@ def __init__(self, opCredsContext: ctypes.c_void_p, fabricId: int, nodeId: int,
1760
1778
1761
1779
self ._dmLib .pychip_DeviceController_SetIssueNOCChainCallbackPythonCallback (_IssueNOCChainCallbackPythonCallback )
1762
1780
1781
+ pairingDelegate = c_void_p (None )
1763
1782
devCtrl = c_void_p (None )
1764
1783
1765
1784
c_catTags = (c_uint32 * len (catTags ))()
@@ -1771,15 +1790,15 @@ def __init__(self, opCredsContext: ctypes.c_void_p, fabricId: int, nodeId: int,
1771
1790
self ._externalKeyPair = keypair
1772
1791
self ._ChipStack .Call (
1773
1792
lambda : self ._dmLib .pychip_OpCreds_AllocateController (c_void_p (
1774
- opCredsContext ), pointer (devCtrl ), fabricId , nodeId , adminVendorId , c_char_p (None if len (paaTrustStorePath ) == 0 else str .encode (paaTrustStorePath )), useTestCommissioner , self ._ChipStack .enableServerInteractions , c_catTags , len (catTags ), None if keypair is None else keypair .native_object )
1793
+ opCredsContext ), pointer (devCtrl ), pointer ( pairingDelegate ), fabricId , nodeId , adminVendorId , c_char_p (None if len (paaTrustStorePath ) == 0 else str .encode (paaTrustStorePath )), useTestCommissioner , self ._ChipStack .enableServerInteractions , c_catTags , len (catTags ), None if keypair is None else keypair .native_object )
1775
1794
).raise_on_error ()
1776
1795
1777
1796
self ._fabricAdmin = fabricAdmin
1778
1797
self ._fabricId = fabricId
1779
1798
self ._nodeId = nodeId
1780
1799
self ._caIndex = fabricAdmin .caIndex
1781
1800
1782
- self ._set_dev_ctrl (devCtrl = devCtrl )
1801
+ self ._set_dev_ctrl (devCtrl = devCtrl , pairingDelegate = pairingDelegate )
1783
1802
1784
1803
self ._finish_init ()
1785
1804
@@ -1925,9 +1944,10 @@ def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
1925
1944
1926
1945
self ._ChipStack .commissioningCompleteEvent .clear ()
1927
1946
1947
+ self ._enablePairingCompeleteCallback (True )
1928
1948
self ._ChipStack .CallAsync (
1929
1949
lambda : self ._dmLib .pychip_DeviceController_OnNetworkCommission (
1930
- self .devCtrl , nodeId , setupPinCode , int (filterType ), str (filter ).encode ("utf-8" ) + b"\x00 " if filter is not None else None , discoveryTimeoutMsec )
1950
+ self .devCtrl , self . pairingDelegate , nodeId , setupPinCode , int (filterType ), str (filter ).encode ("utf-8" ) + b"\x00 " if filter is not None else None , discoveryTimeoutMsec )
1931
1951
)
1932
1952
if not self ._ChipStack .commissioningCompleteEvent .isSet ():
1933
1953
# Error 50 is a timeout
@@ -1948,6 +1968,7 @@ def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType: Disc
1948
1968
1949
1969
self ._ChipStack .commissioningCompleteEvent .clear ()
1950
1970
1971
+ self ._enablePairingCompeleteCallback (True )
1951
1972
self ._ChipStack .CallAsync (
1952
1973
lambda : self ._dmLib .pychip_DeviceController_ConnectWithCode (
1953
1974
self .devCtrl , setupPayload , nodeid , discoveryType .value )
@@ -1967,6 +1988,7 @@ def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> PyChipErr
1967
1988
1968
1989
self ._ChipStack .commissioningCompleteEvent .clear ()
1969
1990
1991
+ self ._enablePairingCompeleteCallback (True )
1970
1992
self ._ChipStack .CallAsync (
1971
1993
lambda : self ._dmLib .pychip_DeviceController_ConnectIP (
1972
1994
self .devCtrl , ipaddr .encode ("utf-8" ), setupPinCode , nodeid )
@@ -2011,6 +2033,7 @@ def __init__(self, operationalKey: p256keypair.P256Keypair, noc: bytes,
2011
2033
'''
2012
2034
super ().__init__ (name or f"ctrl(v/{ adminVendorId } )" )
2013
2035
2036
+ pairingDelegate = c_void_p (None )
2014
2037
devCtrl = c_void_p (None )
2015
2038
2016
2039
# Device should hold a reference to the key to avoid it being GC-ed.
@@ -2019,9 +2042,9 @@ def __init__(self, operationalKey: p256keypair.P256Keypair, noc: bytes,
2019
2042
2020
2043
self ._ChipStack .Call (
2021
2044
lambda : self ._dmLib .pychip_OpCreds_AllocateControllerForPythonCommissioningFLow (
2022
- c_void_p (devCtrl ), nativeKey , noc , len (noc ), icac , len (icac ) if icac else 0 , rcac , len (rcac ), ipk , len (ipk ) if ipk else 0 , adminVendorId , self ._ChipStack .enableServerInteractions )
2045
+ c_void_p (devCtrl ), c_void_p ( pairingDelegate ), nativeKey , noc , len (noc ), icac , len (icac ) if icac else 0 , rcac , len (rcac ), ipk , len (ipk ) if ipk else 0 , adminVendorId , self ._ChipStack .enableServerInteractions )
2023
2046
).raise_on_error ()
2024
2047
2025
- self ._set_dev_ctrl (devCtrl )
2048
+ self ._set_dev_ctrl (devCtrl , pairingDelegate )
2026
2049
2027
2050
self ._finish_init ()
0 commit comments