mirror of
https://github.com/sunnypilot/sunnypilot.git
synced 2026-07-23 20:52:06 +08:00
Platform List: dynamically migrate CarPlatformBundle (#1828)
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user