Skip to content

Commit

Permalink
[python] Fix BLE adapter selection (#5805)
Browse files Browse the repository at this point in the history
  • Loading branch information
erjiaqing authored Apr 7, 2021
1 parent 086bdbb commit 50152f9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/controller/python/chip-device-ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def FormatZCLArguments(args, command):


class DeviceMgrCmd(Cmd):
def __init__(self, rendezvousAddr=None, controllerNodeId=0, bluetoothAdapter=0):
def __init__(self, rendezvousAddr=None, controllerNodeId=0, bluetoothAdapter=None):
self.lastNetworkId = None

Cmd.__init__(self)
Expand All @@ -146,7 +146,7 @@ def __init__(self, rendezvousAddr=None, controllerNodeId=0, bluetoothAdapter=0):
self.devCtrl = ChipDeviceCtrl.ChipDeviceController(controllerNodeId=controllerNodeId, bluetoothAdapter=bluetoothAdapter)

# If we are on Linux and user selects non-default bluetooth adapter.
if sys.platform.startswith("linux") and bluetoothAdapter != 0:
if sys.platform.startswith("linux") and (bluetoothAdapter is not None):
self.bleMgr = BleManager(self.devCtrl)
self.bleMgr.ble_adapter_select("hci{}".format(bluetoothAdapter))

Expand Down Expand Up @@ -599,7 +599,7 @@ def main():
print("Unexpected argument: %s" % remainingArgs[0])
sys.exit(-1)

adapterId = 0
adapterId = None
if sys.platform.startswith("linux"):
if not options.bluetoothAdapter.startswith("hci"):
print("Invalid bluetooth adapter: {}, adapter name looks like hci0, hci1 etc.")
Expand Down
4 changes: 3 additions & 1 deletion src/controller/python/chip/ChipDeviceCtrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class DCState(enum.IntEnum):

@_singleton
class ChipDeviceController(object):
def __init__(self, startNetworkThread=True, controllerNodeId=0, bluetoothAdapter=0):
def __init__(self, startNetworkThread=True, controllerNodeId=0, bluetoothAdapter=None):
self.state = DCState.NOT_INITIALIZED
self.devCtrl = None
if bluetoothAdapter is None:
bluetoothAdapter = 0
self._ChipStack = ChipStack(bluetoothAdapter=bluetoothAdapter)
self._dmLib = None

Expand Down

0 comments on commit 50152f9

Please sign in to comment.