bluetooth service
This commit is contained in:
parent
36fbd1034f
commit
2c8489a0de
@ -13,6 +13,7 @@ DEFAULT_SOUND_VOLUME = 100
|
|||||||
DEFAULT_PREMUTE_VOLUME = 10
|
DEFAULT_PREMUTE_VOLUME = 10
|
||||||
DEFAULT_DUCKING_VOLUME = 35
|
DEFAULT_DUCKING_VOLUME = 35
|
||||||
DEV_MODE_ENABLE = (Path(__file__).resolve().parent / "dev_mode_enable").exists()
|
DEV_MODE_ENABLE = (Path(__file__).resolve().parent / "dev_mode_enable").exists()
|
||||||
|
BLUETOOTH_MAX_PAIRED_DEVICES = 2
|
||||||
|
|
||||||
|
|
||||||
def get_device_model() -> str:
|
def get_device_model() -> str:
|
||||||
|
|||||||
@ -13,6 +13,7 @@ from PySide6.QtWidgets import (
|
|||||||
QScroller,
|
QScroller,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
import build_info
|
||||||
from services.bluetooth_service import BluetoothService, BluetoothDevice
|
from services.bluetooth_service import BluetoothService, BluetoothDevice
|
||||||
|
|
||||||
|
|
||||||
@ -119,6 +120,10 @@ class BluetoothScreen(QWidget):
|
|||||||
success = self._bt_service.make_discoverable()
|
success = self._bt_service.make_discoverable()
|
||||||
if self._bt_service.last_error == "power_off":
|
if self._bt_service.last_error == "power_off":
|
||||||
self.status.setText("Статус: питание BT выключено (проверьте rfkill)")
|
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:
|
elif not success:
|
||||||
self.status.setText(f"Статус: ошибка ({self._bt_service.last_error})")
|
self.status.setText(f"Статус: ошибка ({self._bt_service.last_error})")
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -9,6 +9,8 @@ from pathlib import Path
|
|||||||
|
|
||||||
from PySide6.QtCore import QObject, Signal
|
from PySide6.QtCore import QObject, Signal
|
||||||
|
|
||||||
|
import build_info
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class BluetoothDevice:
|
class BluetoothDevice:
|
||||||
@ -80,7 +82,16 @@ class BluetoothService(QObject):
|
|||||||
return success
|
return success
|
||||||
|
|
||||||
def make_discoverable(self) -> bool:
|
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 = ""
|
self._last_error = ""
|
||||||
script_out = self._run_btctl_script(
|
script_out = self._run_btctl_script(
|
||||||
[
|
[
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user