Skip to content

Commit

Permalink
Check for pairing differently on newer bluez versions
Browse files Browse the repository at this point in the history
  • Loading branch information
tcamise-gpsw committed Aug 15, 2023
1 parent 2b4de8e commit 1ce9aae
Showing 1 changed file with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import logging
import platform
import threading
from packaging.version import Version
from typing import Pattern, Any, Callable, Optional

import pexpect
Expand Down Expand Up @@ -307,9 +308,18 @@ async def _async_def_pair() -> None:
if logger.level == logging.DEBUG:
bluetoothctl.logfile = sys.stdout.buffer
bluetoothctl.expect("Agent registered")
# Get the version
bluetoothctl.sendline("version")
bluetoothctl.expect(r"Version")
bluetoothctl.expect(r"\n")
version = Version(bluetoothctl.before.decode("utf-8").strip())
# First see if we are already paired
bluetoothctl.sendline("paired-devices")
bluetoothctl.expect("paired-devices")
if version >= Version("5.66"):
bluetoothctl.sendline("devices Paired")
bluetoothctl.expect("devices Paired")
else:
bluetoothctl.sendline("paired-devices")
bluetoothctl.expect("paired-devices")
bluetoothctl.expect(r"#")
for device in bluetoothctl.before.decode("utf-8").splitlines():
if "Device" in device and device.split()[1] == handle.address:
Expand Down

0 comments on commit 1ce9aae

Please sign in to comment.