Files
StarPilot/openpilot/starpilot/ui/tests/test_device_actions.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

65 lines
2.6 KiB
Python

"""Request boundaries for the captured large Device viewport."""
from dataclasses import FrozenInstanceError, replace
import unittest
from openpilot.starpilot.ui.device_state import DeviceInput, DeviceRequest, DeviceState, button_rect
from openpilot.starpilot.galaxy.access import AccessStatus
class TestDeviceActions(unittest.TestCase):
def test_galaxy_press_cancels_when_local_state_changes(self):
actions = []
handler = DeviceInput(actions.append)
x, y, width, height = button_rect(DeviceRequest.OPEN_GALAXY)
point = (x + width / 2, y + height / 2)
before = DeviceState(galaxy_status=AccessStatus.UNCONFIGURED)
handler.press(*point, before)
handler.release(*point, replace(before, galaxy_status=AccessStatus.CONFIGURED_LOCAL))
self.assertEqual(actions, [])
def test_each_visible_button_emits_one_typed_request(self):
actions = []
handler = DeviceInput(actions.append)
state = DeviceState()
for request in DeviceRequest:
x, y, width, height = button_rect(request)
point = x + width / 2, y + min(height / 2, 1030 - y - 1)
handler.press(*point, state)
handler.release(*point, state)
handler.release(*point, state)
self.assertEqual(actions[-1].request, request)
self.assertEqual(len(actions), len(DeviceRequest))
def test_disabled_and_cancelled_controls_do_not_emit(self):
actions = []
handler = DeviceInput(actions.append)
camera = (1980, 650)
handler.press(*camera, replace(DeviceState(), offroad=False))
handler.release(*camera, replace(DeviceState(), offroad=False))
handler.press(*camera, DeviceState())
handler.move(1800, 650, DeviceState())
handler.release(*camera, DeviceState())
handler.press(*camera, DeviceState())
handler.release(*camera, replace(DeviceState(), offroad=False))
self.assertEqual(actions, [])
def test_values_are_supplied_and_state_is_immutable(self):
state = replace(DeviceState(), dongle_id="fixture", serial="fixture")
self.assertEqual((state.dongle_id, state.serial), ("fixture", "fixture"))
with self.assertRaises(FrozenInstanceError):
state.serial = "changed" # ty: ignore[invalid-assignment]
def test_pair_and_manage_both_request_the_galaxy_entry(self):
actions = []
handler = DeviceInput(actions.append)
for paired in (False, True):
state = replace(DeviceState(), galaxy_paired=paired)
handler.press(1980, 475, state)
handler.release(1980, 475, state)
self.assertEqual([action.request for action in actions], [DeviceRequest.OPEN_GALAXY] * 2)
if __name__ == "__main__":
unittest.main()