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>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user