pilot_drive.services.bluetooth package

Submodules

pilot_drive.services.bluetooth.bluetooth module

Module for the Bluetooth service

class pilot_drive.services.bluetooth.bluetooth.Bluetooth(master_event_queue: MasterEventQueue, service_type: EventType, logger: MasterLogger, bus: MessageBus | None = None)

Bases: AbstractService

The service that manages the DBus Bluetooth APIs of PILOT Drive.

property active_ancs_devices: List[str]
Get a list of all connected devices that have Apple Notification Center Service (ANCS)

capabilities

Returns:

a list of connected device MAC addresses capable of ANCS

property bluez_adapter: BluezAdapter

Get the BlueZ Adapter1

Returns:

a BluezAdapter instance

property bluez_media_player: BluezMediaPlayer

Get the BlueZ MediaPlayer1

Returns:

a BluezMediaPlayer instance

get_bluez_device(path: ObjPath, props_changed_callback: Callable) BluetoothDevice

Create a new BluetoothDevice instace from a BlueZ device path

Parameters:
  • path – The path to the BlueZ device

  • props_changed_callback – the callback to connect for when device properties change

static get_bus_and_bluez_root(bus: MessageBus | None = None) Tuple[MessageBus, Any]

Get a new instance of the DBus system bus along with the BlueZ root

Parameters:

bus – Provide an optional bus to create a BlueZ root from

Returns:

a tuple with the DBus system bus along with the BlueZ root

main() None

Currently a do-nothing method but may get it’s own loop eventually.

push_bluetooth_to_queue(devices: List[BluetoothDevice]) None

Push bluetooth information to the queue

Parameters:

devices – A list of devices track by the external service using bluetooth. This is temporary and will likely be integrated into the Bluetooth service itself soon.

refresh() None

Pushes stored bluetooth data to queue

class pilot_drive.services.bluetooth.bluetooth.BluetoothDevice(bluez_device: BluezDevice, path: ObjPath, props_changed_callback: Callable, logger: MasterLogger, ancs: bool = False)

Bases: object

Dataclass used to store information and states on BlueZ devices.

address: str
alias: str
ancs: bool = False
bluez_device: BluezDevice
connected: bool
logger: MasterLogger
media: bool
name: str | None = None
path: ObjPath
prop_changed(interface: str, changes: Dict[str, Variant], invalidated_properties: List[str]) None

The callback used when a BlueZ device property changed to update internal states

Parameters:
  • interface – the interface that changed

  • changes – the changes to device properties

Invalidated_properties:

a list of invalidated properties

props_changed_callback: Callable
serialize() Dict

Serializes the BluetoothDevice Object

Returns:

a dict of the device’s informational attributes.

pilot_drive.services.bluetooth.constants module

Constants used for Bluetooth functionality.

Most are hardcoded strings created in hopes to mitigate string typo errors (and enums are cool!)

class pilot_drive.services.bluetooth.constants.PowerStates(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Enum used for the power states of the Adapter iface

PowerStates docs: https://github.com/bluez/bluez/blob/master/doc/adapter-api.txt#L280-#L285

OFF = 'off'
OFF_BLOCKED = 'off-blocked'
OFF_ENABLING = 'off-enabling'
ON = 'on'
ON_DISABLING = 'on-disabling'
class pilot_drive.services.bluetooth.constants.WSCommands(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

Bases: StrEnum

Enum used to map different commands from the websocket

POWER_OFF = 'off-power'
POWER_ON = 'on-power'
START_DISCOVERY = 'start-discovery'
STOP_DISCOVERY = 'stop-discovery'

pilot_drive.services.bluetooth.exceptions module

Exceptions of the Bluetooth service

exception pilot_drive.services.bluetooth.exceptions.NoAdapterException

Bases: Exception

Raised when there is no BlueZ adapter found on DBus

exception pilot_drive.services.bluetooth.exceptions.NoPlayerException

Bases: Exception

Raised when there is no BlueZ media player found on DBus

Module contents

The module that manages the connected bluetooth device and it’s metadata