ble - add function to restart bluetooth.service and add exception handler in _discover device
This commit is contained in:
1 parent
b5834b3eaf
commit
5a9b26556a
1 file changed
+9
@@ -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
|
||||
|
||||
Reference in new issue
Block a user