From 540f4f593382b521dcc0dcf6dc1a9afb2328d866 Mon Sep 17 00:00:00 2001 From: Jason Wen Date: Tue, 5 May 2026 20:27:11 -0400 Subject: [PATCH] Platform List: dynamically migrate CarPlatformBundle (#1828) --- sunnypilot/system/params_migration.py | 35 +++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/sunnypilot/system/params_migration.py b/sunnypilot/system/params_migration.py index 5e524de06e..5d5c75ffeb 100644 --- a/sunnypilot/system/params_migration.py +++ b/sunnypilot/system/params_migration.py @@ -4,7 +4,10 @@ Copyright (c) 2021-, Haibin Wen, sunnypilot, and a number of other contributors. This file is part of sunnypilot and is licensed under the MIT License. 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 ONROAD_BRIGHTNESS_MIGRATION_VERSION: str = "1.0" ONROAD_BRIGHTNESS_TIMER_MIGRATION_VERSION: str = "1.0" @@ -14,6 +17,36 @@ ONROAD_BRIGHTNESS_TIMER_VALUES = {0: 3, 1: 5, 2: 7, 3: 10, 4: 15, 5: 30, **{i: ( VALID_TIMER_VALUES = set(ONROAD_BRIGHTNESS_TIMER_VALUES.values()) +def _migrate_car_platform_bundle(_params): + bundle = _params.get("CarPlatformBundle") + if bundle is None: + return + + old_platform = bundle.get("platform") + if not old_platform: + return + + from opendbc.car.fingerprints import MIGRATION # lazy: avoids heavy import at module level + if old_platform not in MIGRATION: + return + + new_platform = str(MIGRATION[old_platform]) + + with open(CAR_LIST_JSON_OUT) as f: + car_list = json.load(f) + + candidates = [(k, v) for k, v in car_list.items() if v.get("platform") == new_platform] + if candidates: + old_model = bundle.get("model") + key, data = next(((k, v) for k, v in candidates if v.get("model") == old_model), candidates[0]) + bundle = {**data, "name": key} + else: + bundle["platform"] = new_platform + + _params.put("CarPlatformBundle", bundle) + cloudlog.info(f"params_migration: CarPlatformBundle migrated {old_platform!r} -> {new_platform!r}") + + def run_migration(_params): # migrate OnroadScreenOffBrightness if _params.get("OnroadScreenOffBrightnessMigrated") != ONROAD_BRIGHTNESS_MIGRATION_VERSION: @@ -45,3 +78,5 @@ def run_migration(_params): cloudlog.info(log_str + f" Setting OnroadScreenOffTimerMigrated to {ONROAD_BRIGHTNESS_TIMER_MIGRATION_VERSION}") except Exception as e: cloudlog.exception(f"Error migrating OnroadScreenOffTimer: {e}") + + _migrate_car_platform_bundle(_params)