Skip to content

Commit

Permalink
Add raise_on_error to existing calls and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing committed Oct 18, 2022
1 parent 69bb325 commit ae312d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 28 deletions.
6 changes: 4 additions & 2 deletions src/controller/python/chip/ChipCommissionableNodeCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,18 @@ def __del__(self):
self.commissionableNodeCtrl = None

def PrintDiscoveredCommissioners(self):
return self._ChipStack.Call(
# void function
self._ChipStack.Call(
lambda: self._dmLib.pychip_CommissionableNodeController_PrintDiscoveredCommissioners(
self.commissionableNodeCtrl)
)

def DiscoverCommissioners(self):
return self._ChipStack.Call(
res = self._ChipStack.Call(
lambda: self._dmLib.pychip_CommissionableNodeController_DiscoverCommissioners(
self.commissionableNodeCtrl)
)
res.raise_on_error()

# ----- Private Members -----
def _InitLib(self):
Expand Down
30 changes: 5 additions & 25 deletions src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def localSessionId(self) -> int:

builtins.chipStack.Call(
lambda: self._dmLib.pychip_GetLocalSessionId(self._deviceProxy, pointer(localSessionId))
)
).raise_on_error()

return localSessionId.value

Expand All @@ -190,7 +190,7 @@ def numTotalSessions(self) -> int:

builtins.chipStack.Call(
lambda: self._dmLib.pychip_GetNumSessionsToPeer(self._deviceProxy, pointer(numSessions))
)
).raise_on_error()

return numSessions.value

Expand Down Expand Up @@ -331,7 +331,7 @@ def Shutdown(self):
self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_DeleteDeviceController(
self.devCtrl)
)
).raise_on_error()
self.devCtrl = None

ChipDeviceController.activeList.remove(self)
Expand Down Expand Up @@ -372,18 +372,6 @@ def IsConnected(self):
self.devCtrl)
)

def ConnectBle(self, bleConnection):
self.CheckIsActive()

self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_ValidateBTP(
self.devCtrl,
bleConnection,
self._ChipStack.cbHandleComplete,
self._ChipStack.cbHandleError,
)
)

def ConnectBLE(self, discriminator, setupPinCode, nodeid):
self.CheckIsActive()

Expand All @@ -393,7 +381,7 @@ def ConnectBLE(self, discriminator, setupPinCode, nodeid):
self._ChipStack.CallAsync(
lambda: self._dmLib.pychip_DeviceController_ConnectBLE(
self.devCtrl, discriminator, setupPinCode, nodeid)
)
).raise_on_error()
if not self._ChipStack.commissioningCompleteEvent.isSet():
# Error 50 is a timeout
return False
Expand Down Expand Up @@ -596,6 +584,7 @@ def GetAddressAndPort(self, nodeid):
address = create_string_buffer(64)
port = c_uint16(0)

# Intentially return None instead of raising exceptions on error
error = self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_GetAddressAndPort(
self.devCtrl, nodeid, address, 64, pointer(port))
Expand Down Expand Up @@ -716,15 +705,6 @@ def HandleDevice(deviceJson, deviceJsonLen):

return self._ChipStack.Call(lambda: GetDevices(self))

def ParseQRCode(self, qrCode, output):
self.CheckIsActive()

print(output)
return self._ChipStack.Call(
lambda: self._dmLib.pychip_DeviceController_ParseQRCode(
qrCode, output)
)

def GetIPForDiscoveredDevice(self, idx, addrStr, length):
self.CheckIsActive()

Expand Down
2 changes: 1 addition & 1 deletion src/controller/python/chip/ChipStack.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ def setLogFunct(self, logFunct):
self._ChipStackLib.pychip_Stack_SetLogFunct(logFunct)

def Shutdown(self):
self.Call(lambda: self._ChipStackLib.pychip_DeviceController_StackShutdown())
self.Call(lambda: self._ChipStackLib.pychip_DeviceController_StackShutdown()).raise_on_error()

#
# We only shutdown the persistent storage layer AFTER we've shut down the stack,
Expand Down

0 comments on commit ae312d6

Please sign in to comment.