fix: Refactor pairing agent to only trust devices

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-30 22:38:43 +00:00
parent aed90db5e8
commit d9f5c7382b

19
main.py
View File

@@ -62,13 +62,13 @@ class Agent(ServiceInterface):
async def RequestConfirmation(self, device: 'o', passkey: 'u'):
logging.info(f"RequestConfirmation for {device} with passkey {passkey}")
# Automatically confirm and trust
asyncio.create_task(trust_and_connect_device(device))
asyncio.create_task(trust_device(device))
@method()
async def RequestAuthorization(self, device: 'o'):
logging.info(f"RequestAuthorization for {device}")
# Automatically authorize and trust
asyncio.create_task(trust_and_connect_device(device))
asyncio.create_task(trust_device(device))
@method()
async def AuthorizeService(self, device: 'o', uuid: 's'):
@@ -82,24 +82,17 @@ class Agent(ServiceInterface):
def Cancel(self):
logging.info('Pairing Cancelled')
async def trust_and_connect_device(device_path):
logging.info(f'Trusting and connecting to {device_path}')
async def trust_device(device_path):
logging.info(f'Trusting device {device_path}')
try:
introspection = await bus.introspect(BLUEZ_SERVICE, device_path)
device_obj = bus.get_proxy_object(BLUEZ_SERVICE, device_path, introspection)
device_props = device_obj.get_interface('org.freedesktop.DBus.Properties')
await device_props.call_set(DEVICE_IFACE, 'Trusted', Variant('b', True))
logging.info(f'Trusted device {device_path}')
device_iface = device_obj.get_interface(DEVICE_IFACE)
await asyncio.sleep(2)
await device_iface.call_connect()
logging.info(f'Connected to device {device_path}')
except Exception as e:
logging.error(f'Failed to trust/connect to {device_path}: {e}')
logging.error(f'Failed to trust device {device_path}: {e}')
async def get_adapter():
introspection = await bus.introspect(BLUEZ_SERVICE, '/')