Skip to content

Commit 34e0f29

Browse files
authored
Merge pull request #788 from zxzxwu/device
Fix wrong with_connection_from_address parameter
2 parents f8223ca + 85215df commit 34e0f29

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

bumble/device.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,7 +2171,7 @@ def with_connection_from_address(function):
21712171
@functools.wraps(function)
21722172
def wrapper(device: Device, address: hci.Address, *args, **kwargs):
21732173
if connection := device.pending_connections.get(address):
2174-
return function(device, connection, address, *args, **kwargs)
2174+
return function(device, connection, *args, **kwargs)
21752175
for connection in device.connections.values():
21762176
if connection.peer_address == address:
21772177
return function(device, connection, *args, **kwargs)
@@ -6443,18 +6443,14 @@ def on_cs_procedure(self, event: hci.HCI_LE_CS_Procedure_Enable_Complete_Event):
64436443

64446444
# [Classic only]
64456445
@host_event_handler
6446-
@try_with_connection_from_address
6446+
@with_connection_from_address
64476447
def on_role_change(
64486448
self,
6449-
connection: Optional[Connection],
6450-
peer_address: hci.Address,
6449+
connection: Connection,
64516450
new_role: hci.Role,
64526451
):
6453-
if connection:
6454-
connection.role = new_role
6455-
connection.emit(connection.EVENT_ROLE_CHANGE, new_role)
6456-
else:
6457-
logger.warning("Role change to unknown connection %s", peer_address)
6452+
connection.role = new_role
6453+
connection.emit(connection.EVENT_ROLE_CHANGE, new_role)
64586454

64596455
# [Classic only]
64606456
@host_event_handler

tests/device_test.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,34 @@ async def test_inquiry_result_with_rssi():
761761
m.assert_called_with(hci.Address("00:11:22:33:44:55/P"), 3, mock.ANY, 5)
762762

763763

764+
# -----------------------------------------------------------------------------
765+
@pytest.mark.parametrize(
766+
"roles",
767+
(
768+
(hci.Role.PERIPHERAL, hci.Role.CENTRAL),
769+
(hci.Role.CENTRAL, hci.Role.PERIPHERAL),
770+
),
771+
)
772+
@pytest.mark.asyncio
773+
async def test_accept_classic_connection(roles: tuple[hci.Role, hci.Role]):
774+
devices = TwoDevices()
775+
devices[0].classic_enabled = True
776+
devices[1].classic_enabled = True
777+
await devices[0].power_on()
778+
await devices[1].power_on()
779+
780+
accept_task = asyncio.create_task(devices[1].accept(role=roles[1]))
781+
await devices[0].connect(
782+
devices[1].public_address, transport=PhysicalTransport.BR_EDR
783+
)
784+
await accept_task
785+
786+
assert devices.connections[0]
787+
assert devices.connections[0].role == roles[0]
788+
assert devices.connections[1]
789+
assert devices.connections[1].role == roles[1]
790+
791+
764792
# -----------------------------------------------------------------------------
765793
async def run_test_device():
766794
await test_device_connect_parallel()

0 commit comments

Comments
 (0)