Files
openpilot-evo/sunnypilot/system/params_migration.py
T
Jason Wen 29a3b3315f ui: reimplement "Screen Off" option to Onroad Brightness (#1732)
* ui: Add "Screen Off" option to Onroad Brightness

* migrate old value

* bruh

* fix algo

* comment

* no
2026-02-28 00:18:35 -05:00

28 lines
1.1 KiB
Python

"""
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.
"""
from openpilot.common.swaglog import cloudlog
ONROAD_BRIGHTNESS_MIGRATION_VERSION: str = "1.0"
def run_migration(_params):
# migrate OnroadScreenOffBrightness
if _params.get("OnroadScreenOffBrightnessMigrated") != ONROAD_BRIGHTNESS_MIGRATION_VERSION:
try:
val = _params.get("OnroadScreenOffBrightness")
if val >= 2: # old: 5%, new: Screen Off
new_val = val + 1
_params.put("OnroadScreenOffBrightness", new_val)
log_str = f"Successfully migrated OnroadScreenOffBrightness from {val} to {new_val}."
else:
log_str = "Migration not required for OnroadScreenOffBrightness."
_params.put("OnroadScreenOffBrightnessMigrated", ONROAD_BRIGHTNESS_MIGRATION_VERSION)
cloudlog.info(log_str + f" Setting OnroadScreenOffBrightnessMigrated to {ONROAD_BRIGHTNESS_MIGRATION_VERSION}")
except Exception as e:
cloudlog.exception(f"Error migrating OnroadScreenOffBrightness: {e}")