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:
19
main.py
19
main.py
@@ -62,13 +62,13 @@ class Agent(ServiceInterface):
|
|||||||
async def RequestConfirmation(self, device: 'o', passkey: 'u'):
|
async def RequestConfirmation(self, device: 'o', passkey: 'u'):
|
||||||
logging.info(f"RequestConfirmation for {device} with passkey {passkey}")
|
logging.info(f"RequestConfirmation for {device} with passkey {passkey}")
|
||||||
# Automatically confirm and trust
|
# Automatically confirm and trust
|
||||||
asyncio.create_task(trust_and_connect_device(device))
|
asyncio.create_task(trust_device(device))
|
||||||
|
|
||||||
@method()
|
@method()
|
||||||
async def RequestAuthorization(self, device: 'o'):
|
async def RequestAuthorization(self, device: 'o'):
|
||||||
logging.info(f"RequestAuthorization for {device}")
|
logging.info(f"RequestAuthorization for {device}")
|
||||||
# Automatically authorize and trust
|
# Automatically authorize and trust
|
||||||
asyncio.create_task(trust_and_connect_device(device))
|
asyncio.create_task(trust_device(device))
|
||||||
|
|
||||||
@method()
|
@method()
|
||||||
async def AuthorizeService(self, device: 'o', uuid: 's'):
|
async def AuthorizeService(self, device: 'o', uuid: 's'):
|
||||||
@@ -82,24 +82,17 @@ class Agent(ServiceInterface):
|
|||||||
def Cancel(self):
|
def Cancel(self):
|
||||||
logging.info('Pairing Cancelled')
|
logging.info('Pairing Cancelled')
|
||||||
|
|
||||||
async def trust_and_connect_device(device_path):
|
async def trust_device(device_path):
|
||||||
logging.info(f'Trusting and connecting to {device_path}')
|
logging.info(f'Trusting device {device_path}')
|
||||||
try:
|
try:
|
||||||
introspection = await bus.introspect(BLUEZ_SERVICE, device_path)
|
introspection = await bus.introspect(BLUEZ_SERVICE, device_path)
|
||||||
device_obj = bus.get_proxy_object(BLUEZ_SERVICE, device_path, introspection)
|
device_obj = bus.get_proxy_object(BLUEZ_SERVICE, device_path, introspection)
|
||||||
|
|
||||||
device_props = device_obj.get_interface('org.freedesktop.DBus.Properties')
|
device_props = device_obj.get_interface('org.freedesktop.DBus.Properties')
|
||||||
await device_props.call_set(DEVICE_IFACE, 'Trusted', Variant('b', True))
|
await device_props.call_set(DEVICE_IFACE, 'Trusted', Variant('b', True))
|
||||||
logging.info(f'Trusted device {device_path}')
|
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:
|
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():
|
async def get_adapter():
|
||||||
introspection = await bus.introspect(BLUEZ_SERVICE, '/')
|
introspection = await bus.introspect(BLUEZ_SERVICE, '/')
|
||||||
|
|||||||
Reference in New Issue
Block a user