v0.1.38: Comprehensive Bluetooth recovery for persistent connection failures\n\n- Added automatic Bluetooth stack reset (cache + service restart) for BLE errors\n- Enhanced recovery logic with final connection attempt after reset\n- Improved error messages with specific host_dbus configuration guidance\n- Maintained all previous fixes for Classic Bluetooth and BLE scanning\n- Updated version to 0.1.38 with detailed CHANGELOG\n\nGenerated by Mistral Vibe.\nCo-Authored-By: Mistral Vibe <vibe@mistral.ai>
Some checks failed
Deploy to GitHub Pages / build (push) Has been cancelled
Deploy to GitHub Pages / deploy (push) Has been cancelled

This commit is contained in:
paul2212
2026-03-18 19:29:05 +01:00
parent c86a185ec4
commit 4ad06c30cb
4 changed files with 62 additions and 4 deletions

View File

@@ -519,9 +519,44 @@ async def connect(
if attempt < BLE_CONNECT_RETRIES:
await asyncio.sleep(BLE_CONNECT_BACKOFF * attempt)
continue
# Enhanced recovery for persistent BLE issues
if attempt == BLE_CONNECT_RETRIES:
print(
"BLE connection persistently failing. "
"Attempting comprehensive Bluetooth stack reset..."
)
try:
# Comprehensive Bluetooth reset
reset_commands = [
f'echo -e "remove {address}\nquit" | bluetoothctl',
"sudo systemctl restart bluetooth",
"sleep 3",
f'echo -e "scan on\nscan off\nquit" | bluetoothctl"
]
for cmd in reset_commands:
proc = await asyncio.create_subprocess_shell(
cmd,
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL,
)
await asyncio.wait_for(proc.communicate(), timeout=15.0)
print("Bluetooth stack reset completed. Retrying connection...")
target = await resolve_ble_target(address)
# One final attempt after reset
async with BleakClient(target) as client:
pc = PrinterClient(client)
await pc.start()
yield pc
return
except Exception as reset_exc:
print(f"Comprehensive reset failed: {reset_exc}")
raise PrinterError(
"BLE connection failed (br-connection-not-supported) after LE rescan. "
"Try Classic Bluetooth with classic=true and channel=1."
"BLE connection failed (br-connection-not-supported) after comprehensive recovery. "
"This typically indicates missing host_dbus permissions in Home Assistant. "
"Please ensure your add-on configuration includes: host_dbus: true"
) from exc
last_exc = exc
if _is_retryable_ble_error(exc) and attempt < BLE_CONNECT_RETRIES: