Get comprehensive Bluetooth status Returns detailed status information
(self)
| 82 | return False, f"Error checking Bluetooth: {str(e)}" |
| 83 | |
| 84 | def get_status(self) -> Dict[str, Any]: |
| 85 | """ |
| 86 | Get comprehensive Bluetooth status |
| 87 | Returns detailed status information |
| 88 | """ |
| 89 | status = { |
| 90 | 'enabled': False, |
| 91 | 'discoverable': False, |
| 92 | 'pairable': False, |
| 93 | 'scanning': self.scan_active, |
| 94 | 'address': None, |
| 95 | 'name': None, |
| 96 | 'class': None, |
| 97 | 'powered': False, |
| 98 | 'error': None, |
| 99 | 'controller_info': {}, |
| 100 | 'os_type': self.os_type |
| 101 | } |
| 102 | |
| 103 | try: |
| 104 | if self._is_windows(): |
| 105 | # Windows-specific Bluetooth status check |
| 106 | ps_script = """ |
| 107 | $adapters = Get-PnpDevice -Class Bluetooth -Status OK |
| 108 | if ($adapters) { |
| 109 | $adapter = $adapters | Select-Object -First 1 |
| 110 | $info = @{ |
| 111 | Name = $adapter.FriendlyName |
| 112 | Status = $adapter.Status |
| 113 | InstanceId = $adapter.InstanceId |
| 114 | } |
| 115 | Write-Output ($info | ConvertTo-Json) |
| 116 | } |
| 117 | """ |
| 118 | |
| 119 | result = subprocess.run(['powershell', '-NoProfile', '-Command', ps_script], |
| 120 | capture_output=True, text=True, timeout=10) |
| 121 | |
| 122 | if result.returncode == 0 and result.stdout.strip(): |
| 123 | try: |
| 124 | adapter_info = json.loads(result.stdout.strip()) |
| 125 | status['enabled'] = adapter_info.get('Status', '').upper() == 'OK' |
| 126 | status['powered'] = status['enabled'] |
| 127 | status['name'] = adapter_info.get('Name', 'Windows Bluetooth Adapter') |
| 128 | status['controller_info'] = adapter_info |
| 129 | |
| 130 | self.logger.info(f"Windows Bluetooth adapter found: {status['name']}") |
| 131 | except json.JSONDecodeError: |
| 132 | status['enabled'] = True # Assume enabled if we got output |
| 133 | status['powered'] = True |
| 134 | else: |
| 135 | status['error'] = 'No Bluetooth adapter found on Windows' |
| 136 | self.logger.warning("No Bluetooth adapter available on Windows") |
| 137 | |
| 138 | # Windows scanning status |
| 139 | status['scanning'] = self.scan_active |
| 140 | |
| 141 | else: |
no test coverage detected