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

Method power_on

actions/ble.py:207–239  ·  view source on GitHub ↗

Enable/Power on Bluetooth Returns: (success, message)

(self)

Source from the content-addressed store, hash-verified

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 """

Callers 4

start_scanMethod · 0.95
enable_bluetoothFunction · 0.80
executeMethod · 0.80
ble.pyFile · 0.80

Calls 6

get_statusMethod · 0.95
infoMethod · 0.80
warningMethod · 0.80
errorMethod · 0.80
runMethod · 0.45
sleepMethod · 0.45

Tested by

no test coverage detected