Enable/Power on Bluetooth Returns: (success, message)
(self)
| 205 | return None |
| 206 | |
| 207 | def power_on(self) -> Tuple[bool, str]: |
| 208 | """ |
| 209 | Enable/Power on Bluetooth |
| 210 | Returns: (success, message) |
| 211 | """ |
| 212 | try: |
| 213 | self.logger.info("Enabling Bluetooth...") |
| 214 | result = subprocess.run(['bluetoothctl', 'power', 'on'], |
| 215 | capture_output=True, text=True, timeout=15) |
| 216 | |
| 217 | if result.returncode == 0: |
| 218 | # Wait a moment for Bluetooth to stabilize |
| 219 | time.sleep(2) |
| 220 | |
| 221 | # Verify it's actually enabled |
| 222 | status = self.get_status() |
| 223 | if status['enabled']: |
| 224 | self.logger.info("Bluetooth enabled successfully") |
| 225 | return True, "Bluetooth enabled successfully" |
| 226 | else: |
| 227 | self.logger.warning("Bluetooth command succeeded but device not powered") |
| 228 | return False, "Bluetooth power on command succeeded but device not enabled" |
| 229 | else: |
| 230 | error_msg = result.stderr.strip() or 'Failed to enable Bluetooth' |
| 231 | self.logger.error(f"Failed to enable Bluetooth: {error_msg}") |
| 232 | return False, error_msg |
| 233 | |
| 234 | except subprocess.TimeoutExpired: |
| 235 | self.logger.error("Bluetooth enable command timed out") |
| 236 | return False, "Enable Bluetooth command timed out" |
| 237 | except Exception as e: |
| 238 | self.logger.error(f"Error enabling Bluetooth: {e}") |
| 239 | return False, f"Error enabling Bluetooth: {str(e)}" |
| 240 | |
| 241 | def power_off(self) -> Tuple[bool, str]: |
| 242 | """ |
no test coverage detected