Files
StarPilot/openpilot/starpilot/bluetooth/tests/test_onroad_management.py
T
firestar5683 a82935f326 User interfaces and Android Auto
Integrate onroad views, configurable widgets, local settings, steering-profile contracts, Bluetooth and Android Auto with their device and runtime services.

Co-authored-by: Adeeb Shihadeh <adeebshihadeh@gmail.com>
Co-authored-by: Daniel Koepping <elkoled@gmail.com>
Co-authored-by: Danny <dannyirwin31@yahoo.com>
Co-authored-by: DimitriChrysafis <Dimitri.chrysafis@gmail.com>
Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com>
Co-authored-by: Harald Schäfer <harald.the.engineer@gmail.com>
Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu>
Co-authored-by: Shane Smiskol <shane@smiskol.com>
Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com>
Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com>
Co-authored-by: stef <19478336+stefpi@users.noreply.github.com>
Co-authored-by: whoisdomi <dcantu83@gmail.com>

Co-authored-by: Intelli <contact@intelli.software>
Co-authored-by: pharmacomaniac <blittle65@gmail.com>

Co-authored-by: prabhaavp <prabhaav@msu.edu>
2026-10-14 20:02:39 -05:00

37 lines
1.7 KiB
Python

"""Device management stays usable onroad; radio service restart stays parked."""
import tempfile
from pathlib import Path
from unittest.mock import Mock
import pytest
from openpilot.starpilot.bluetooth.owner import BluetoothOwner, BluetoothRejected
from openpilot.starpilot.bluetooth.radio_preference import RadioPreference
from openpilot.starpilot.bluetooth.tests.test_owner import FakeBlueZ, FakeTimer
def test_actual_owner_runtime_operations_and_restart_gate():
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
helper = root / 'bluetooth-radio'
helper.write_bytes(b'helper')
FakeBlueZ.devices = [{'address': 'AA:BB:CC:DD:EE:FF', 'name': 'car', 'paired': True,
'connected': False, 'trusted': True}]
FakeBlueZ.operations = []
owner = BluetoothOwner(lambda: False, bluez_factory=FakeBlueZ, radio_helper=helper,
systemctl=Mock(), radio_preference=RadioPreference(root / 'BluetoothEnabled'),
timer_factory=FakeTimer, admission_lock=root / 'adapter.lock')
try:
assert owner.snapshot()['parked'] is False
owner.request('scan')
assert owner.scan_deadline > 0
owner.request('stop_scan')
owner.request('connect', address='AA:BB:CC:DD:EE:FF')
assert owner.snapshot()['devices'][0]['connected'] is True
owner.request('disconnect', address='AA:BB:CC:DD:EE:FF')
assert owner.snapshot()['devices'][0]['connected'] is False
with pytest.raises(BluetoothRejected, match='radio restart requires Park'):
owner.request('power', enabled=False)
owner.request('forget', address='AA:BB:CC:DD:EE:FF')
assert owner.snapshot()['devices'] == []
finally:
owner.close()