diff --git a/main.py b/main.py index 2bede4f..b287414 100644 --- a/main.py +++ b/main.py @@ -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, '/')