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

Method power_off

actions/ble.py:241–269  ·  view source on GitHub ↗

Disable/Power off Bluetooth Returns: (success, message)

(self)

Source from the content-addressed store, hash-verified

239 return False, f"Error enabling Bluetooth: {str(e)}"
240
241 def power_off(self) -> Tuple[bool, str]:
242 """
243 Disable/Power off Bluetooth
244 Returns: (success, message)
245 """
246 try:
247 self.logger.info("Disabling Bluetooth...")
248
249 # Stop scanning if active
250 if self.scan_active:
251 self.stop_scan()
252
253 result = subprocess.run(['bluetoothctl', 'power', 'off'],
254 capture_output=True, text=True, timeout=15)
255
256 if result.returncode == 0:
257 self.logger.info("Bluetooth disabled successfully")
258 return True, "Bluetooth disabled successfully"
259 else:
260 error_msg = result.stderr.strip() or 'Failed to disable Bluetooth'
261 self.logger.error(f"Failed to disable Bluetooth: {error_msg}")
262 return False, error_msg
263
264 except subprocess.TimeoutExpired:
265 self.logger.error("Bluetooth disable command timed out")
266 return False, "Disable Bluetooth command timed out"
267 except Exception as e:
268 self.logger.error(f"Error disabling Bluetooth: {e}")
269 return False, f"Error disabling Bluetooth: {str(e)}"
270
271 def set_discoverable(self, discoverable: bool) -> Tuple[bool, str]:
272 """

Callers 1

disable_bluetoothFunction · 0.80

Calls 4

stop_scanMethod · 0.95
infoMethod · 0.80
errorMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected