Fix scanner fallback logic when DBus fails

The fallback wasn't being triggered because when mode='auto' was
replaced with the recommended backend ('dbus'), the fallback condition
failed. Now properly tracks original_mode to allow fallback.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-01-21 15:49:09 +00:00
parent 28d15d0ed5
commit c49b1e03f2
+6 -4
View File
@@ -106,15 +106,17 @@ class BluetoothScanner:
# Select and start backend # Select and start backend
started = False started = False
backend_used = None backend_used = None
original_mode = mode
if mode == 'auto': if mode == 'auto':
mode = self._capabilities.recommended_backend mode = self._capabilities.recommended_backend or 'bleak'
if mode == 'dbus' or (mode == 'auto' and self._capabilities.has_dbus): if mode == 'dbus':
started, backend_used = self._start_dbus(adapter, transport, rssi_threshold) started, backend_used = self._start_dbus(adapter, transport, rssi_threshold)
if not started and mode in ('bleak', 'hcitool', 'bluetoothctl', 'auto'): # Fallback: try non-DBus methods if DBus failed or wasn't requested
started, backend_used = self._start_fallback(adapter, mode) if not started and (original_mode == 'auto' or mode in ('bleak', 'hcitool', 'bluetoothctl')):
started, backend_used = self._start_fallback(adapter, original_mode)
if not started: if not started:
self._status.error = f"Failed to start scanner with mode '{mode}'" self._status.error = f"Failed to start scanner with mode '{mode}'"