I AM SCREAMING

This commit is contained in:
firestar5683
2026-07-02 16:38:13 -05:00
parent 5bbe5f1daf
commit ea2aa532af
18 changed files with 173 additions and 1187 deletions
+6 -61
View File
@@ -1,69 +1,14 @@
#!/usr/bin/env python3
from pathlib import Path
from openpilot.system.hardware import HARDWARE
BIG_UI_DEVICE_TYPES = ("tici", "tizi")
SMALL_UI_DEVICE_TYPE = "mici"
def _normalize_device_type(raw: str) -> str:
device_type = raw.replace("\x00", "").strip().lower()
if "comma " in device_type:
device_type = device_type.rsplit("comma ", 1)[-1].strip()
return device_type
def _device_tree_device_type() -> str | None:
model_path = Path("/sys/firmware/devicetree/base/model")
if not model_path.is_file():
return None
try:
return _normalize_device_type(model_path.read_text(encoding="utf-8", errors="ignore"))
except Exception:
return None
def _reported_device_type() -> str | None:
try:
return _normalize_device_type(HARDWARE.get_device_type())
except Exception:
return None
def _ui_device_type() -> str:
device_tree_type = _device_tree_device_type()
if device_tree_type in BIG_UI_DEVICE_TYPES:
return device_tree_type
if device_tree_type:
return SMALL_UI_DEVICE_TYPE
reported_type = _reported_device_type()
if reported_type in BIG_UI_DEVICE_TYPES:
return reported_type
return SMALL_UI_DEVICE_TYPE
def _patch_hardware_device_type(device_type: str) -> None:
HARDWARE.get_device_type = lambda: device_type
try:
import openpilot.system.hardware.tici.hardware as tici_hardware
tici_hardware.get_device_type = lambda: device_type
except Exception:
pass
from openpilot.system.ui.lib.application import gui_app
import openpilot.system.ui.tici_reset as tici_reset
import openpilot.system.ui.mici_reset as mici_reset
def main():
device_type = _ui_device_type()
_patch_hardware_device_type(device_type)
if device_type in BIG_UI_DEVICE_TYPES:
import openpilot.system.ui.tici_reset as reset_impl
if gui_app.big_ui():
tici_reset.main()
else:
import openpilot.system.ui.mici_reset as reset_impl
reset_impl.main()
mici_reset.main()
if __name__ == "__main__":
-42
View File
@@ -1,42 +0,0 @@
import importlib
import sys
import types
from unittest.mock import patch
import pytest
@pytest.fixture
def reset_module(monkeypatch):
hardware = types.ModuleType("openpilot.system.hardware")
hardware.HARDWARE = types.SimpleNamespace(get_device_type=lambda: "tici")
monkeypatch.setitem(sys.modules, "openpilot.system.hardware", hardware)
sys.modules.pop("openpilot.system.ui.reset", None)
module = importlib.import_module("openpilot.system.ui.reset")
yield module
sys.modules.pop("openpilot.system.ui.reset", None)
def test_device_tree_tici_uses_big_ui(reset_module):
with patch.object(reset_module, "_device_tree_device_type", return_value="tici"), \
patch.object(reset_module, "_reported_device_type", return_value="mici"):
assert reset_module._ui_device_type() == "tici"
def test_device_tree_tizi_uses_big_ui(reset_module):
with patch.object(reset_module, "_device_tree_device_type", return_value="tizi"), \
patch.object(reset_module, "_reported_device_type", return_value="mici"):
assert reset_module._ui_device_type() == "tizi"
@pytest.mark.parametrize("device_tree_type", ["mici", "comma 4", "comma four"])
def test_non_tici_device_tree_uses_small_ui(reset_module, device_tree_type):
with patch.object(reset_module, "_device_tree_device_type", return_value=device_tree_type), \
patch.object(reset_module, "_reported_device_type", return_value="tici"):
assert reset_module._ui_device_type() == "mici"
def test_reported_tici_used_when_no_device_tree(reset_module):
with patch.object(reset_module, "_device_tree_device_type", return_value=None), \
patch.object(reset_module, "_reported_device_type", return_value="tici"):
assert reset_module._ui_device_type() == "tici"