Fix wrong with_connection_from_address parameter

This commit is contained in:
Josh Wu
2025-09-23 17:17:36 +08:00
parent f8223ca81f
commit 85215df2c3
2 changed files with 33 additions and 9 deletions

View File

@@ -2171,7 +2171,7 @@ def with_connection_from_address(function):
@functools.wraps(function)
def wrapper(device: Device, address: hci.Address, *args, **kwargs):
if connection := device.pending_connections.get(address):
return function(device, connection, address, *args, **kwargs)
return function(device, connection, *args, **kwargs)
for connection in device.connections.values():
if connection.peer_address == address:
return function(device, connection, *args, **kwargs)
@@ -6443,18 +6443,14 @@ class Device(utils.CompositeEventEmitter):
# [Classic only]
@host_event_handler
@try_with_connection_from_address
@with_connection_from_address
def on_role_change(
self,
connection: Optional[Connection],
peer_address: hci.Address,
connection: Connection,
new_role: hci.Role,
):
if connection:
connection.role = new_role
connection.emit(connection.EVENT_ROLE_CHANGE, new_role)
else:
logger.warning("Role change to unknown connection %s", peer_address)
connection.role = new_role
connection.emit(connection.EVENT_ROLE_CHANGE, new_role)
# [Classic only]
@host_event_handler