@@ -249,7 +249,10 @@ def future(self) -> typing.Optional[concurrent.futures.Future]:
249
249
250
250
async def __aexit__ (self , exc_type , exc_value , traceback ):
251
251
if not self ._future .done ():
252
- raise RuntimeError ("CallbackContext future not completed" )
252
+ # In case the initial call (which sets up for the callback) fails,
253
+ # the future will never be used actually. So just cancel it here
254
+ # for completeness, in case somebody is expecting it to be completed.
255
+ self ._future .cancel ()
253
256
self ._future = None
254
257
self ._lock .release ()
255
258
@@ -603,23 +606,22 @@ async def ConnectBLE(self, discriminator: int, setupPinCode: int, nodeid: int, i
603
606
604
607
async with self ._commissioning_context as ctx :
605
608
self ._enablePairingCompleteCallback (True )
606
- res = await self ._ChipStack .CallAsync (
609
+ await self ._ChipStack .CallAsync (
607
610
lambda : self ._dmLib .pychip_DeviceController_ConnectBLE (
608
611
self .devCtrl , discriminator , isShortDiscriminator , setupPinCode , nodeid )
609
612
)
610
- res .raise_on_error ()
611
613
612
614
return await asyncio .futures .wrap_future (ctx .future )
613
615
614
616
async def UnpairDevice (self , nodeid : int ) -> None :
615
617
self .CheckIsActive ()
616
618
617
619
async with self ._unpair_device_context as ctx :
618
- res = await self ._ChipStack .CallAsync (
620
+ await self ._ChipStack .CallAsync (
619
621
lambda : self ._dmLib .pychip_DeviceController_UnpairDevice (
620
622
self .devCtrl , nodeid , self .cbHandleDeviceUnpairCompleteFunct )
621
623
)
622
- res . raise_on_error ()
624
+
623
625
return await asyncio .futures .wrap_future (ctx .future )
624
626
625
627
def CloseBLEConnection (self ):
@@ -656,8 +658,7 @@ async def _establishPASESession(self, callFunct):
656
658
657
659
async with self ._pase_establishment_context as ctx :
658
660
self ._enablePairingCompleteCallback (True )
659
- res = await self ._ChipStack .CallAsync (callFunct )
660
- res .raise_on_error ()
661
+ await self ._ChipStack .CallAsync (callFunct )
661
662
await asyncio .futures .wrap_future (ctx .future )
662
663
663
664
async def EstablishPASESessionBLE (self , setupPinCode : int , discriminator : int , nodeid : int ) -> None :
@@ -756,13 +757,12 @@ async def DiscoverCommissionableNodes(self, filterType: discovery.FilterType = d
756
757
# Discovery is also used during commissioning. Make sure this manual discovery
757
758
# and commissioning attempts do not interfere with each other.
758
759
async with self ._commissioning_lock :
759
- res = await self ._ChipStack .CallAsync (
760
+ await self ._ChipStack .CallAsync (
760
761
lambda : self ._dmLib .pychip_DeviceController_DiscoverCommissionableNodes (
761
762
self .devCtrl , int (filterType ), str (filter ).encode ("utf-8" )))
762
- res .raise_on_error ()
763
763
764
764
async def _wait_discovery ():
765
- while not await self ._ChipStack .CallAsync (
765
+ while not await self ._ChipStack .CallAsyncWithResult (
766
766
lambda : self ._dmLib .pychip_DeviceController_HasDiscoveredCommissionableNode (self .devCtrl )):
767
767
await asyncio .sleep (0.1 )
768
768
return
@@ -776,9 +776,8 @@ async def _wait_discovery():
776
776
# Expected timeout, do nothing
777
777
pass
778
778
finally :
779
- res = await self ._ChipStack .CallAsync (
779
+ await self ._ChipStack .CallAsync (
780
780
lambda : self ._dmLib .pychip_DeviceController_StopCommissionableDiscovery (self .devCtrl ))
781
- res .raise_on_error ()
782
781
783
782
return await self .GetDiscoveredDevices ()
784
783
@@ -796,7 +795,7 @@ def HandleDevice(deviceJson, deviceJsonLen):
796
795
self ._dmLib .pychip_DeviceController_IterateDiscoveredCommissionableNodes (devCtrl .devCtrl , HandleDevice )
797
796
return devices
798
797
799
- return await self ._ChipStack .CallAsync (lambda : GetDevices (self ))
798
+ return await self ._ChipStack .CallAsyncWithResult (lambda : GetDevices (self ))
800
799
801
800
def GetIPForDiscoveredDevice (self , idx , addrStr , length ):
802
801
self .CheckIsActive ()
@@ -828,11 +827,10 @@ async def OpenCommissioningWindow(self, nodeid: int, timeout: int, iteration: in
828
827
self .CheckIsActive ()
829
828
830
829
async with self ._open_window_context as ctx :
831
- res = await self ._ChipStack .CallAsync (
830
+ await self ._ChipStack .CallAsync (
832
831
lambda : self ._dmLib .pychip_DeviceController_OpenCommissioningWindow (
833
832
self .devCtrl , self .pairingDelegate , nodeid , timeout , iteration , discriminator , option )
834
833
)
835
- res .raise_on_error ()
836
834
837
835
return await asyncio .futures .wrap_future (ctx .future )
838
836
@@ -896,14 +894,14 @@ async def FindOrEstablishPASESession(self, setupCode: str, nodeid: int, timeoutM
896
894
''' Returns CommissioneeDeviceProxy if we can find or establish a PASE connection to the specified device'''
897
895
self .CheckIsActive ()
898
896
returnDevice = c_void_p (None )
899
- res = await self ._ChipStack .CallAsync (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
897
+ res = await self ._ChipStack .CallAsyncWithResult (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
900
898
self .devCtrl , nodeid , byref (returnDevice )), timeoutMs )
901
899
if res .is_success :
902
900
return DeviceProxyWrapper (returnDevice , DeviceProxyWrapper .DeviceProxyType .COMMISSIONEE , self ._dmLib )
903
901
904
902
await self .EstablishPASESession (setupCode , nodeid )
905
903
906
- res = await self ._ChipStack .CallAsync (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
904
+ res = await self ._ChipStack .CallAsyncWithResult (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
907
905
self .devCtrl , nodeid , byref (returnDevice )), timeoutMs )
908
906
if res .is_success :
909
907
return DeviceProxyWrapper (returnDevice , DeviceProxyWrapper .DeviceProxyType .COMMISSIONEE , self ._dmLib )
@@ -991,7 +989,7 @@ async def GetConnectedDevice(self, nodeid, allowPASE: bool = True, timeoutMs: in
991
989
992
990
if allowPASE :
993
991
returnDevice = c_void_p (None )
994
- res = await self ._ChipStack .CallAsync (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
992
+ res = await self ._ChipStack .CallAsyncWithResult (lambda : self ._dmLib .pychip_GetDeviceBeingCommissioned (
995
993
self .devCtrl , nodeid , byref (returnDevice )), timeoutMs )
996
994
if res .is_success :
997
995
LOGGER .info ('Using PASE connection' )
@@ -1021,10 +1019,9 @@ def deviceAvailable(self, device, err):
1021
1019
1022
1020
closure = DeviceAvailableClosure (eventLoop , future )
1023
1021
ctypes .pythonapi .Py_IncRef (ctypes .py_object (closure ))
1024
- res = await self ._ChipStack .CallAsync (lambda : self ._dmLib .pychip_GetConnectedDeviceByNodeId (
1022
+ await self ._ChipStack .CallAsync (lambda : self ._dmLib .pychip_GetConnectedDeviceByNodeId (
1025
1023
self .devCtrl , nodeid , ctypes .py_object (closure ), _DeviceAvailableCallback ),
1026
1024
timeoutMs )
1027
- res .raise_on_error ()
1028
1025
1029
1026
# The callback might have been received synchronously (during self._ChipStack.CallAsync()).
1030
1027
# In that case the Future has already been set it will return immediately
@@ -1917,11 +1914,10 @@ async def Commission(self, nodeid) -> int:
1917
1914
1918
1915
async with self ._commissioning_context as ctx :
1919
1916
self ._enablePairingCompleteCallback (False )
1920
- res = await self ._ChipStack .CallAsync (
1917
+ await self ._ChipStack .CallAsync (
1921
1918
lambda : self ._dmLib .pychip_DeviceController_Commission (
1922
1919
self .devCtrl , nodeid )
1923
1920
)
1924
- res .raise_on_error ()
1925
1921
1926
1922
return await asyncio .futures .wrap_future (ctx .future )
1927
1923
@@ -2065,11 +2061,10 @@ async def CommissionOnNetwork(self, nodeId: int, setupPinCode: int,
2065
2061
2066
2062
async with self ._commissioning_context as ctx :
2067
2063
self ._enablePairingCompleteCallback (True )
2068
- res = await self ._ChipStack .CallAsync (
2064
+ await self ._ChipStack .CallAsync (
2069
2065
lambda : self ._dmLib .pychip_DeviceController_OnNetworkCommission (
2070
2066
self .devCtrl , self .pairingDelegate , nodeId , setupPinCode , int (filterType ), str (filter ).encode ("utf-8" ) if filter is not None else None , discoveryTimeoutMsec )
2071
2067
)
2072
- res .raise_on_error ()
2073
2068
2074
2069
return await asyncio .futures .wrap_future (ctx .future )
2075
2070
@@ -2086,11 +2081,10 @@ async def CommissionWithCode(self, setupPayload: str, nodeid: int, discoveryType
2086
2081
2087
2082
async with self ._commissioning_context as ctx :
2088
2083
self ._enablePairingCompleteCallback (True )
2089
- res = await self ._ChipStack .CallAsync (
2084
+ await self ._ChipStack .CallAsync (
2090
2085
lambda : self ._dmLib .pychip_DeviceController_ConnectWithCode (
2091
2086
self .devCtrl , setupPayload .encode ("utf-8" ), nodeid , discoveryType .value )
2092
2087
)
2093
- res .raise_on_error ()
2094
2088
2095
2089
return await asyncio .futures .wrap_future (ctx .future )
2096
2090
@@ -2106,11 +2100,10 @@ async def CommissionIP(self, ipaddr: str, setupPinCode: int, nodeid: int) -> int
2106
2100
2107
2101
async with self ._commissioning_context as ctx :
2108
2102
self ._enablePairingCompleteCallback (True )
2109
- res = await self ._ChipStack .CallAsync (
2103
+ await self ._ChipStack .CallAsync (
2110
2104
lambda : self ._dmLib .pychip_DeviceController_ConnectIP (
2111
2105
self .devCtrl , ipaddr .encode ("utf-8" ), setupPinCode , nodeid )
2112
2106
)
2113
- res .raise_on_error ()
2114
2107
2115
2108
return await asyncio .futures .wrap_future (ctx .future )
2116
2109
@@ -2127,11 +2120,11 @@ async def IssueNOCChain(self, csr: Clusters.OperationalCredentials.Commands.CSRR
2127
2120
self .CheckIsActive ()
2128
2121
2129
2122
async with self ._issue_node_chain_context as ctx :
2130
- res = await self ._ChipStack .CallAsync (
2123
+ await self ._ChipStack .CallAsync (
2131
2124
lambda : self ._dmLib .pychip_DeviceController_IssueNOCChain (
2132
2125
self .devCtrl , py_object (self ), csr .NOCSRElements , len (csr .NOCSRElements ), nodeId )
2133
2126
)
2134
- res . raise_on_error ()
2127
+
2135
2128
return await asyncio .futures .wrap_future (ctx .future )
2136
2129
2137
2130
0 commit comments