Try to get devices discovered during active scanning using multiple methods This is a workaround since bluetoothctl devices might not show newly discovered devices
(self)
| 655 | return devices |
| 656 | |
| 657 | def _get_scan_results(self) -> Dict[str, Dict[str, Any]]: |
| 658 | """ |
| 659 | Try to get devices discovered during active scanning using multiple methods |
| 660 | This is a workaround since bluetoothctl devices might not show newly discovered devices |
| 661 | """ |
| 662 | scan_devices = {} |
| 663 | |
| 664 | # Method 1: Use bluetoothctl in batch mode with device listing |
| 665 | try: |
| 666 | # Start a fresh bluetoothctl session that scans and lists devices |
| 667 | ps_script = ''' |
| 668 | import subprocess |
| 669 | import time |
| 670 | import re |
| 671 | |
| 672 | devices = {} |
| 673 | |
| 674 | # Start bluetoothctl process |
| 675 | proc = subprocess.Popen( |
| 676 | ['bluetoothctl'], |
| 677 | stdin=subprocess.PIPE, |
| 678 | stdout=subprocess.PIPE, |
| 679 | stderr=subprocess.PIPE, |
| 680 | text=True, |
| 681 | bufsize=1 |
| 682 | ) |
| 683 | |
| 684 | # Send scan on command |
| 685 | proc.stdin.write('scan on\\n') |
| 686 | proc.stdin.flush() |
| 687 | |
| 688 | # Wait for devices to appear |
| 689 | time.sleep(3) |
| 690 | |
| 691 | # Send devices command |
| 692 | proc.stdin.write('devices\\n') |
| 693 | proc.stdin.flush() |
| 694 | time.sleep(0.5) |
| 695 | |
| 696 | # Send exit |
| 697 | proc.stdin.write('exit\\n') |
| 698 | proc.stdin.flush() |
| 699 | |
| 700 | # Read output |
| 701 | try: |
| 702 | output, _ = proc.communicate(timeout=2) |
| 703 | |
| 704 | # Parse device lines |
| 705 | for line in output.split('\\n'): |
| 706 | line = line.strip() |
| 707 | if line.startswith('Device '): |
| 708 | parts = line.split(None, 2) |
| 709 | if len(parts) >= 2: |
| 710 | addr = parts[1] |
| 711 | name = parts[2] if len(parts) > 2 else 'Unknown Device' |
| 712 | print(f"{addr}|{name}") |
| 713 | except: |
| 714 | pass |
no test coverage detected