Skip to content

BluetoothLocalDevice

Base classes

Name Children Inherits
ObjectMixin
prettyqt.core.object
QBluetoothLocalDevice
PySide6.QtBluetooth
QBluetoothLocalDevice(self, address: PySide6.QtBluetooth.QBluetoothAddress, /, parent: PySide6.QtCore.QObject | None \= None) -> None

â‹” Inheritance diagram

graph TD
  706979133["bluetooth.BluetoothLocalDevice"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  247625454["QtBluetooth.QBluetoothLocalDevice"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  3227531497 --> 706979133
  2751680898 --> 3227531497
  247625454 --> 706979133
  3984060476 --> 247625454
  37984305 --> 3984060476
  2751680898 --> 37984305

🛈 DocStrings

Bases: ObjectMixin, QBluetoothLocalDevice

Enables access to the local Bluetooth device.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
class BluetoothLocalDevice(core.ObjectMixin, bluetooth.QBluetoothLocalDevice):
    """Enables access to the local Bluetooth device."""

    def __bool__(self):
        """Return True when local device is valid."""
        return self.isValid()

    def __repr__(self):
        return get_repr(self, self.address())

    def set_host_mode(self, mode: HostModeStr | HostMode):
        """Set host mode.

        Args:
            mode: host mode to use
        """
        self.setHostMode(HOST_MODE.get_enum_value(mode))

    def get_host_mode(self) -> HostModeStr:
        """Return host mode.

        Returns:
            host mode
        """
        return HOST_MODE.inverse[self.hostMode()]

    def get_pairing_status(
        self, address: bluetooth.QBluetoothAddress | int | str
    ) -> PairingStr:
        """Return pairing status.

        Arguments:
            address: bluetooth address

        Returns:
            pairing status
        """
        if isinstance(address, int | str):
            address = bluetooth.QBluetoothAddress(address)
        return PAIRING.inverse[self.pairingStatus(address)]

    def request_pairing(
        self,
        address: bluetooth.QBluetoothAddress | int | str,
        pairing: PairingStr | Pairing,
    ):
        """Request a pairing to given bluetooth address."""
        if isinstance(address, int | str):
            address = bluetooth.QBluetoothAddress(address)
        self.requestPairing(address, PAIRING.get_enum_value(pairing))

    def get_connected_devices(self) -> list[bluetooth.BluetoothAddress]:
        """Get addresses for connected devices."""
        return [bluetooth.BluetoothAddress(i) for i in self.connectedDevices()]

    @classmethod
    def for_all_devices(cls) -> list[bluetooth.BluetoothHostInfo]:
        """Get host info for all devices."""
        return [bluetooth.BluetoothHostInfo(i) for i in cls.allDevices()]

__bool__()

Return True when local device is valid.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def __bool__(self):
    """Return True when local device is valid."""
    return self.isValid()

for_all_devices() -> list[bluetooth.BluetoothHostInfo] classmethod

Get host info for all devices.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
@classmethod
def for_all_devices(cls) -> list[bluetooth.BluetoothHostInfo]:
    """Get host info for all devices."""
    return [bluetooth.BluetoothHostInfo(i) for i in cls.allDevices()]

get_connected_devices() -> list[bluetooth.BluetoothAddress]

Get addresses for connected devices.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def get_connected_devices(self) -> list[bluetooth.BluetoothAddress]:
    """Get addresses for connected devices."""
    return [bluetooth.BluetoothAddress(i) for i in self.connectedDevices()]

get_host_mode() -> HostModeStr

Return host mode.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def get_host_mode(self) -> HostModeStr:
    """Return host mode.

    Returns:
        host mode
    """
    return HOST_MODE.inverse[self.hostMode()]

get_pairing_status(address: bluetooth.QBluetoothAddress | int | str) -> PairingStr

Return pairing status.

Parameters:

Name Type Description Default
address QBluetoothAddress | int | str

bluetooth address

required
Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def get_pairing_status(
    self, address: bluetooth.QBluetoothAddress | int | str
) -> PairingStr:
    """Return pairing status.

    Arguments:
        address: bluetooth address

    Returns:
        pairing status
    """
    if isinstance(address, int | str):
        address = bluetooth.QBluetoothAddress(address)
    return PAIRING.inverse[self.pairingStatus(address)]

request_pairing(address: bluetooth.QBluetoothAddress | int | str, pairing: PairingStr | Pairing)

Request a pairing to given bluetooth address.

Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def request_pairing(
    self,
    address: bluetooth.QBluetoothAddress | int | str,
    pairing: PairingStr | Pairing,
):
    """Request a pairing to given bluetooth address."""
    if isinstance(address, int | str):
        address = bluetooth.QBluetoothAddress(address)
    self.requestPairing(address, PAIRING.get_enum_value(pairing))

set_host_mode(mode: HostModeStr | HostMode)

Set host mode.

Parameters:

Name Type Description Default
mode HostModeStr | HostMode

host mode to use

required
Source code in prettyqt/bluetooth/bluetoothlocaldevice.py
def set_host_mode(self, mode: HostModeStr | HostMode):
    """Set host mode.

    Args:
        mode: host mode to use
    """
    self.setHostMode(HOST_MODE.get_enum_value(mode))

:fa-brands-github: Show source on GitHub