From 78007e82e077980865e4f1aac29432999bef1818 Mon Sep 17 00:00:00 2001 From: Nayan Date: Mon, 11 May 2026 01:19:10 -0400 Subject: [PATCH] ui: show default model name (#1837) * py py py * sunnylink too * refactor * this is not needed anymore * mici mici * ugh * retry CI * ui: refactor default model name handling Move DEFAULT_MODEL constant into sunnypilot/models/default_model.py and remove the one-liner common/model.py. Strip the hardcoded " (Default)" suffix from the constant value so each UI site appends it contextually, keeping the raw model name clean for the schema payload to sunnylink. Replace the DefaultModel param approach with schema["default_model"] injected at schema assembly time, eliminating a redundant param write on every sunnylinkd start. Remove DefaultModel from params_keys.h and params_metadata.json. Update update_default_model_name() to do a targeted regex replacement instead of overwriting the whole file, since the constant now lives in a module with other code. --------- Co-authored-by: Jason Wen --- common/model.h | 1 - selfdrive/ui/sunnypilot/layouts/settings/models.py | 5 +++-- selfdrive/ui/sunnypilot/mici/layouts/models.py | 9 ++++++--- sunnypilot/models/default_model.py | 10 +++++----- sunnypilot/models/model_name.py | 1 + ...sync_car_list_param.py => sync_sunnylink_params.py} | 0 sunnypilot/sunnylink/athena/sunnylinkd.py | 4 +++- sunnypilot/system/params_migration.py | 2 +- 8 files changed, 19 insertions(+), 13 deletions(-) delete mode 100644 common/model.h create mode 100644 sunnypilot/models/model_name.py rename sunnypilot/selfdrive/car/{sync_car_list_param.py => sync_sunnylink_params.py} (100%) diff --git a/common/model.h b/common/model.h deleted file mode 100644 index d134ebd15e..0000000000 --- a/common/model.h +++ /dev/null @@ -1 +0,0 @@ -#define DEFAULT_MODEL "POP model (Default)" diff --git a/selfdrive/ui/sunnypilot/layouts/settings/models.py b/selfdrive/ui/sunnypilot/layouts/settings/models.py index adbd99f1f3..81f1c47db2 100644 --- a/selfdrive/ui/sunnypilot/layouts/settings/models.py +++ b/selfdrive/ui/sunnypilot/layouts/settings/models.py @@ -10,6 +10,7 @@ import time import pyray as rl from cereal import custom +from openpilot.sunnypilot.models.default_model import DEFAULT_MODEL from openpilot.common.constants import CV from openpilot.selfdrive.ui.ui_state import device, ui_state from openpilot.system.ui.lib.multilang import tr @@ -207,7 +208,7 @@ class ModelsLayout(Widget): for bundle in bundles: folders.setdefault(next((ov_ride.value for ov_ride in bundle.overrides if ov_ride.key == "folder"), ""), []).append(bundle) - folders_list = [TreeFolder("", [TreeNode("Default", {'display_name': tr("Default Model"), 'short_name': "Default"})])] + folders_list = [TreeFolder("", [TreeNode("Default", {'display_name': f"{DEFAULT_MODEL} (Default)", 'short_name': "Default"})])] for folder, folder_bundles in sorted(folders.items(), key=lambda x: max((bundle.index for bundle in x[1]), default=-1), reverse=True): folder_bundles.sort(key=lambda bundle: bundle.index, reverse=True) name = folder + (f" - (Updated: {m.group(1)})" if folder_bundles and (m := re.search(r'\(([^)]*)\)[^(]*$', folder_bundles[0].displayName)) else "") @@ -243,7 +244,7 @@ class ModelsLayout(Widget): self._update_lagd_description(live_delay) self.model_manager = ui_state.sm["modelManagerSP"] self._handle_bundle_download_progress() - active_name = self.model_manager.activeBundle.internalName if self.model_manager and self.model_manager.activeBundle.ref else tr("Default Model") + active_name = self.model_manager.activeBundle.internalName if self.model_manager and self.model_manager.activeBundle.ref else f"{DEFAULT_MODEL} (Default)" self.current_model_item.action_item.set_value(active_name) if not ui_state.is_offroad(): diff --git a/selfdrive/ui/sunnypilot/mici/layouts/models.py b/selfdrive/ui/sunnypilot/mici/layouts/models.py index 331743416f..7f3d9a065b 100644 --- a/selfdrive/ui/sunnypilot/mici/layouts/models.py +++ b/selfdrive/ui/sunnypilot/mici/layouts/models.py @@ -8,6 +8,7 @@ from collections.abc import Callable import pyray as rl from cereal import custom +from openpilot.sunnypilot.models.default_model import DEFAULT_MODEL from openpilot.selfdrive.ui.mici.widgets.button import BigButton from openpilot.selfdrive.ui.sunnypilot.layouts.settings.models import ModelsLayout from openpilot.selfdrive.ui.ui_state import ui_state, device @@ -27,7 +28,8 @@ class CurrentModelInfo(Widget): subheader_color = rl.Color(255, 255, 255, int(255 * 0.9 * 0.65)) max_width = int(self._rect.width - 20) self.current_model_header = UnifiedLabel(tr("active model"), 48, max_width=max_width, text_color=header_color, font_weight=FontWeight.DISPLAY) - self.current_model_text = UnifiedLabel(tr("default model"), 32, max_width=max_width, text_color=subheader_color, font_weight=FontWeight.ROMAN, scroll=True) + default_text = f"{DEFAULT_MODEL} (Default)".lower() + self.current_model_text = UnifiedLabel(default_text, 32, max_width=max_width, text_color=subheader_color, font_weight=FontWeight.ROMAN, scroll=True) self.info_header = UnifiedLabel("cache size", 48, max_width=max_width, text_color=header_color, font_weight=FontWeight.DISPLAY) self.info_text = UnifiedLabel("0 mb", 32, max_width=max_width, text_color=subheader_color, font_weight=FontWeight.ROMAN) @@ -98,7 +100,7 @@ class ModelsLayoutMici(NavScroller): folders = self._get_grouped_bundles(favorites) folder_buttons = [] - default_btn = BigButton(tr("default model")) + default_btn = BigButton(f"{DEFAULT_MODEL} (Default)".lower()) default_btn.set_click_callback(self._select_default) folder_buttons.append(default_btn) @@ -168,7 +170,8 @@ class ModelsLayoutMici(NavScroller): self._was_downloading = is_downloading self.current_model_info.current_model_header.set_text(tr("active model")) - self.current_model_info.current_model_text.set_text(manager.activeBundle.displayName.lower() if manager.activeBundle.index > 0 else tr("default model")) + model_text = manager.activeBundle.displayName.lower() if manager.activeBundle.index > 0 else f"{DEFAULT_MODEL} (Default)".lower() + self.current_model_info.current_model_text.set_text(model_text) self.current_model_info.info_header.set_text(tr("cache size")) self.current_model_info.info_text.set_text(f"{ModelsLayout.calculate_cache_size():.2f} MB") diff --git a/sunnypilot/models/default_model.py b/sunnypilot/models/default_model.py index 0260a3c3bc..f0469a4601 100755 --- a/sunnypilot/models/default_model.py +++ b/sunnypilot/models/default_model.py @@ -4,8 +4,9 @@ import hashlib from openpilot.common.basedir import BASEDIR from openpilot.sunnypilot import get_file_hash +from openpilot.sunnypilot.models.model_name import DEFAULT_MODEL -DEFAULT_MODEL_NAME_PATH = os.path.join(BASEDIR, "common", "model.h") +DEFAULT_MODEL_NAME_PATH = os.path.join(BASEDIR, "sunnypilot", "models", "model_name.py") MODEL_HASH_PATH = os.path.join(BASEDIR, "sunnypilot", "models", "tests", "model_hash") VISION_ONNX_PATH = os.path.join(BASEDIR, "selfdrive", "modeld", "models", "driving_vision.onnx") POLICY_ONNX_PATH = os.path.join(BASEDIR, "selfdrive", "modeld", "models", "driving_policy.onnx") @@ -25,8 +26,7 @@ def update_model_hash(): def get_current_default_model_name(): print("[GET DEFAULT MODEL NAME]") - with open(DEFAULT_MODEL_NAME_PATH) as f: - name = f.read().split('"')[1] + name = DEFAULT_MODEL print(f'Current default model name: "{name}"') return name @@ -35,7 +35,7 @@ def get_current_default_model_name(): def update_default_model_name(name: str): print("[CHANGE DEFAULT MODEL NAME]") with open(DEFAULT_MODEL_NAME_PATH, "w") as f: - f.write(f'#define DEFAULT_MODEL "{name}"\n') + f.write(f'DEFAULT_MODEL = "{name}"\n') print(f'New default model name: "{name}"') print("[DONE]") @@ -51,7 +51,7 @@ if __name__ == "__main__": exit(0) current_name = get_current_default_model_name() - new_name = f"{args.new_name} (Default)" + new_name = args.new_name if current_name == new_name: print(f'Proposed default model name: "{new_name}"') confirm = input("Proposed default model name is the same as the current default model name. Confirm? (y/n): ").upper().strip() diff --git a/sunnypilot/models/model_name.py b/sunnypilot/models/model_name.py new file mode 100644 index 0000000000..2d9c549763 --- /dev/null +++ b/sunnypilot/models/model_name.py @@ -0,0 +1 @@ +DEFAULT_MODEL = "POP model" diff --git a/sunnypilot/selfdrive/car/sync_car_list_param.py b/sunnypilot/selfdrive/car/sync_sunnylink_params.py similarity index 100% rename from sunnypilot/selfdrive/car/sync_car_list_param.py rename to sunnypilot/selfdrive/car/sync_sunnylink_params.py diff --git a/sunnypilot/sunnylink/athena/sunnylinkd.py b/sunnypilot/sunnylink/athena/sunnylinkd.py index b896d26ab4..5e7b400d97 100755 --- a/sunnypilot/sunnylink/athena/sunnylinkd.py +++ b/sunnypilot/sunnylink/athena/sunnylinkd.py @@ -28,7 +28,8 @@ from websocket import (ABNF, WebSocket, WebSocketException, WebSocketTimeoutExce create_connection, WebSocketConnectionClosedException) import cereal.messaging as messaging -from openpilot.sunnypilot.selfdrive.car.sync_car_list_param import update_car_list_param +from openpilot.sunnypilot.models.default_model import DEFAULT_MODEL +from openpilot.sunnypilot.selfdrive.car.sync_sunnylink_params import update_car_list_param from openpilot.sunnypilot.sunnylink.api import SunnylinkApi from openpilot.sunnypilot.sunnylink.utils import sunnylink_need_register, sunnylink_ready, get_param_as_byte, save_param_from_base64_encoded_string from openpilot.sunnypilot.sunnylink.capabilities import generate_capabilities, CAPABILITY_LABELS @@ -214,6 +215,7 @@ def getParamsMetadata() -> str: schema = generate_schema() schema["capabilities"] = generate_capabilities() schema["capability_labels"] = CAPABILITY_LABELS + schema["default_model"] = DEFAULT_MODEL raw = json.dumps(schema, separators=(",", ":")).encode("utf-8") return base64.b64encode(gzip.compress(raw)).decode("utf-8") except Exception: diff --git a/sunnypilot/system/params_migration.py b/sunnypilot/system/params_migration.py index 5d5c75ffeb..2f796c174e 100644 --- a/sunnypilot/system/params_migration.py +++ b/sunnypilot/system/params_migration.py @@ -7,7 +7,7 @@ See the LICENSE.md file in the root directory for more details. import json from openpilot.common.swaglog import cloudlog -from openpilot.sunnypilot.selfdrive.car.sync_car_list_param import CAR_LIST_JSON_OUT +from openpilot.sunnypilot.selfdrive.car.sync_sunnylink_params import CAR_LIST_JSON_OUT ONROAD_BRIGHTNESS_MIGRATION_VERSION: str = "1.0" ONROAD_BRIGHTNESS_TIMER_MIGRATION_VERSION: str = "1.0"