From 725615f59daceb76da6cd8b44cb22b8ffa563dbd Mon Sep 17 00:00:00 2001 From: alejandrogs73 Date: Thu, 1 Oct 2026 17:55:29 +0200 Subject: [PATCH] =?UTF-8?q?bluetooth:=20re-emparejar=20si=20el=20dispositi?= =?UTF-8?q?vo=20olvid=C3=B3=20la=20clave?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Si los auriculares pierden el emparejamiento (p. ej. al emparejarlos con otro aparato) el PC sigue viéndolos como Paired: yes y connect falla siempre con br-connection-key-missing. Ahora, ante ese error, se borra el dispositivo, se busca, se vuelve a emparejar y se conecta. Co-Authored-By: Claude Opus 5.5 --- home/.local/bin/bluetooth | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/home/.local/bin/bluetooth b/home/.local/bin/bluetooth index 4d531ab..fb1b398 100755 --- a/home/.local/bin/bluetooth +++ b/home/.local/bin/bluetooth @@ -21,13 +21,22 @@ emparejar() { } # conectar MAC: si no está emparejado lo empareja; si no está a la vista, lo -# busca unos segundos y lo vuelve a intentar. +# busca unos segundos y lo vuelve a intentar. Si el dispositivo ha olvidado el +# emparejamiento (br-connection-key-missing), lo borra y lo empareja de nuevo. conectar() { if ! bluetoothctl info "$1" | grep -q 'Paired: yes'; then emparejar "$1" || { buscar 8 && emparejar "$1"; } || return 1 fi - bluetoothctl connect "$1" >/dev/null || - { buscar 8 && bluetoothctl connect "$1" >/dev/null; } + salida=$(bluetoothctl connect "$1" 2>&1) && return 0 + case $salida in + *key-missing*) + bluetoothctl remove "$1" >/dev/null + buscar 8 && emparejar "$1" && bluetoothctl connect "$1" >/dev/null + ;; + *) + buscar 8 && bluetoothctl connect "$1" >/dev/null + ;; + esac } # conectar_y_avisar "Nombre (MAC)"