(request: WSGIRequest)
return HttpResponse("Disconnected")
Untrusts a given bluetooth device to prevent automatic reconnects.
    Does not unpair or remove the device.
Untrusts a given bluetooth device to prevent automatic reconnects.
    Does not unpair or remove the device.
Untrusts a given bluetooth device to prevent automatic reconnects . Does not unpair or remove the device .
def disconnect_bluetooth(request: WSGIRequest) -> HttpResponse:
    """Untrusts a given bluetooth device to prevent automatic reconnects.
    Does not unpair or remove the device."""
    address = request.POST.get("address")
    if address is None or address == "":
        return HttpResponseBadRequest("No device selected")
    bluetoothctl = _start_bluetoothctl()
    if not bluetoothctl:
        return HttpResponseBadRequest("Stop scanning before disconnecting")
    assert bluetoothctl.stdin
    error = ""

    bluetoothctl.stdin.write(b"untrust " + address.encode() + b"\n")
    bluetoothctl.stdin.flush()
    while True:
        line = _get_bluetoothctl_line(bluetoothctl)
        if not line:
            break
        if re.match(".*Device " + address + " not available", line):
            error = "Device unavailable"
            break
        if re.match(".*untrust succeeded", line):
            break

    _stop_bluetoothctl(bluetoothctl)
    if error:
        return HttpResponseBadRequest(error)
    return HttpResponse("Disconnected")
def disconnect_bluetooth ( request : WSGIRequest ) -> HttpResponse : address = request . POST . get ( "address" ) if address is None or address == "" : return HttpResponseBadRequest ( "No device selected" ) bluetoothctl = _start_bluetoothctl ( ) if not bluetoothctl : return HttpResponseBadRequest ( "Stop scanning before disconnecting" ) assert bluetoothctl . stdin error = "" bluetoothctl . stdin . write ( b"untrust " + address . encode ( ) + b"\n" ) bluetoothctl . stdin . flush ( ) while True : line = _get_bluetoothctl_line ( bluetoothctl ) if not line : break if re . match ( ".*Device " + address + " not available" , line ) : error = "Device unavailable" break if re . match ( ".*untrust succeeded" , line ) : break _stop_bluetoothctl ( bluetoothctl ) if error : return HttpResponseBadRequest ( error ) return HttpResponse ( "Disconnected" )