fix: Attempt disconnect before connecting Bluetooth devices

Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
2025-12-30 21:44:40 +00:00
parent c3c2fc794c
commit 2e68948f09

View File

@@ -92,6 +92,15 @@ async def trust_and_connect_device(device_path):
logging.info(f'Trusted device {device_path}')
device_iface = device_obj.get_interface(DEVICE_IFACE)
try:
logging.info(f"Attempting to disconnect {device_path} before connecting.")
await device_iface.call_disconnect()
await asyncio.sleep(1) # Give it a moment to settle
except DBusError as e:
# This is expected if the device is not already connected.
logging.info(f"Disconnect failed (this is likely okay): {e}")
await device_iface.call_connect()
logging.info(f'Connected to device {device_path}')
except Exception as e: