bluetooth service

This commit is contained in:
cheykrym 2026-03-31 23:18:38 +03:00
parent 36fbd1034f
commit 2c8489a0de
3 changed files with 18 additions and 1 deletions

View File

@ -13,6 +13,7 @@ DEFAULT_SOUND_VOLUME = 100
DEFAULT_PREMUTE_VOLUME = 10
DEFAULT_DUCKING_VOLUME = 35
DEV_MODE_ENABLE = (Path(__file__).resolve().parent / "dev_mode_enable").exists()
BLUETOOTH_MAX_PAIRED_DEVICES = 2
def get_device_model() -> str:

View File

@ -13,6 +13,7 @@ from PySide6.QtWidgets import (
QScroller,
)
import build_info
from services.bluetooth_service import BluetoothService, BluetoothDevice
@ -119,6 +120,10 @@ class BluetoothScreen(QWidget):
success = self._bt_service.make_discoverable()
if self._bt_service.last_error == "power_off":
self.status.setText("Статус: питание BT выключено (проверьте rfkill)")
elif self._bt_service.last_error == "max_devices":
self.status.setText(
f"Статус: достигнуто макс. число устройств ({build_info.BLUETOOTH_MAX_PAIRED_DEVICES})"
)
elif not success:
self.status.setText(f"Статус: ошибка ({self._bt_service.last_error})")
else:

View File

@ -9,6 +9,8 @@ from pathlib import Path
from PySide6.QtCore import QObject, Signal
import build_info
@dataclass
class BluetoothDevice:
@ -80,7 +82,16 @@ class BluetoothService(QObject):
return success
def make_discoverable(self) -> bool:
"""Сделать устройство видимым для сопряжения."""
"""Сделать устройство видимым для сопряжения.
Возвращает False, если достигнуто максимальное количество сопряженных устройств.
"""
# Проверка лимита сопряженных устройств
paired_devices = self.get_paired_devices()
if len(paired_devices) >= build_info.BLUETOOTH_MAX_PAIRED_DEVICES:
self._last_error = "max_devices"
return False
self._last_error = ""
script_out = self._run_btctl_script(
[