diff --git a/api/ble.py b/api/ble.py index bc4d21e..c797867 100644 --- a/api/ble.py +++ b/api/ble.py @@ -106,6 +106,8 @@ async def _discover_device(mac: str) -> Optional[str]: except Exception as e: log.error(f"Dicvoere call failed - {e}") reset_adapter() + if "org.freedesktop.DBus.Error.AccessDenied" in e: + restart_bt_service() return None # Don't question the ancient magic @@ -182,6 +184,13 @@ def reset_adapter(): log.warning("Hmm, this shouldn't happen, the current_usb_id is blank 0_o") log.info("Reset complete. ") +# this restarts the bluetooth service +def restart_bt_service(): + log.info("Resetting bluetooth.service...") + log.info(subprocess.run(["systemctl", "stop", "bluetooth.service"], capture_output=True, text=True, check=True).stdout.strip()) + time.sleep(2) + log.info(subprocess.run(["systemctl", "start", "bluetooth.service"], capture_output=True, text=True, check=True).stdout.strip()) + #################################################### # Core async read functions # Mined directly from the javascript