From e3bf7c4b5368832f4ac57ad0326f3c98eaa6b42f Mon Sep 17 00:00:00 2001 From: Josh Wu Date: Wed, 20 Jul 2022 21:28:48 +0800 Subject: [PATCH] Refactor find_connection_by_bd_addr * Compare only address bytes because Address.__eq__ also compares types. * Add a transport field to find connection to a device on specific transport. (It's possible to connect a device on both BR/EDR and LE) --- bumble/device.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bumble/device.py b/bumble/device.py index 974f542..f834f9e 100644 --- a/bumble/device.py +++ b/bumble/device.py @@ -484,10 +484,11 @@ class Device(CompositeEventEmitter): if connection := self.connections.get(connection_handle): return connection - def find_connection_by_bd_addr(self, bd_addr): + def find_connection_by_bd_addr(self, bd_addr, transport=None): for connection in self.connections.values(): - if connection.peer_address == bd_addr: - return connection + if connection.peer_address.get_bytes() == bd_addr.get_bytes(): + if transport is None or connection.transport == transport: + return connection def register_l2cap_server(self, psm, server): self.l2cap_channel_manager.register_server(psm, server)