MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / diagnose_scanning

Method diagnose_scanning

actions/ble.py:877–947  ·  view source on GitHub ↗

Diagnose why Bluetooth scanning might not be finding devices Returns diagnostic information

(self)

Source from the content-addressed store, hash-verified

875 return scan_devices
876
877 def diagnose_scanning(self) -> Dict[str, Any]:
878 """
879 Diagnose why Bluetooth scanning might not be finding devices
880 Returns diagnostic information
881 """
882 diagnosis = {
883 'bluetooth_available': False,
884 'bluetooth_enabled': False,
885 'scanning_active': False,
886 'controller_info': {},
887 'recommendations': [],
888 'os_type': self.os_type
889 }
890
891 try:
892 # Check basic availability
893 available, msg = self.check_bluetooth_availability()
894 diagnosis['bluetooth_available'] = available
895 if not available:
896 diagnosis['recommendations'].append(f"Bluetooth not available: {msg}")
897 return diagnosis
898
899 # Check status
900 status = self.get_status()
901 diagnosis['bluetooth_enabled'] = status.get('enabled', False)
902 diagnosis['scanning_active'] = status.get('scanning', False)
903 diagnosis['controller_info'] = status.get('controller_info', {})
904
905 if not diagnosis['bluetooth_enabled']:
906 diagnosis['recommendations'].append("Bluetooth is not enabled. Try enabling it first.")
907
908 if not diagnosis['scanning_active']:
909 diagnosis['recommendations'].append("Scanning is not active. Start a scan to discover devices.")
910
911 # Check for paired devices as a baseline
912 paired = self.get_paired_devices()
913 diagnosis['paired_device_count'] = len(paired)
914
915 if len(paired) == 0:
916 diagnosis['recommendations'].append("No paired devices found. This might indicate Bluetooth setup issues.")
917
918 # Platform-specific diagnostics
919 if self._is_windows():
920 diagnosis['recommendations'].append("Running on Windows - using PowerShell Bluetooth APIs")
921 diagnosis['recommendations'].append("Make sure devices are in pairing/discoverable mode")
922 else:
923 # Test basic bluetoothctl functionality (Linux)
924 try:
925 result = subprocess.run(['bluetoothctl', 'list'],
926 capture_output=True, text=True, timeout=5)
927 diagnosis['controllers_found'] = result.returncode == 0 and len(result.stdout.strip()) > 0
928 if not diagnosis['controllers_found']:
929 diagnosis['recommendations'].append("No Bluetooth controllers found. Check hardware.")
930 except Exception:
931 diagnosis['controllers_found'] = False
932 diagnosis['recommendations'].append("Cannot communicate with bluetoothctl. Check installation.")
933
934 # Add general recommendations

Callers 1

diagnose_bluetoothFunction · 0.80

Calls 8

get_statusMethod · 0.95
get_paired_devicesMethod · 0.95
_is_windowsMethod · 0.95
appendMethod · 0.80
extendMethod · 0.80
getMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected