mirror of
https://github.com/infiniteCable2/openpilot.git
synced 2026-08-06 00:36:29 +08:00
params: auto decode based on type (#35794)
* type * test * more * might as well use this * one more * live * athena * b * also * more * now * ah * pigeon
This commit is contained in:
@@ -470,7 +470,7 @@ def setRouteViewed(route: str) -> dict[str, int | str]:
|
||||
# maintain a list of the last 10 routes viewed in connect
|
||||
params = Params()
|
||||
|
||||
r = params.get("AthenadRecentlyViewedRoutes", encoding="utf8")
|
||||
r = params.get("AthenadRecentlyViewedRoutes")
|
||||
routes = [] if r is None else r.split(",")
|
||||
routes.append(route)
|
||||
|
||||
@@ -492,7 +492,7 @@ def startLocalProxy(global_end_event: threading.Event, remote_ws_uri: str, local
|
||||
|
||||
cloudlog.debug("athena.startLocalProxy.starting")
|
||||
|
||||
dongle_id = Params().get("DongleId").decode('utf8')
|
||||
dongle_id = Params().get("DongleId")
|
||||
identity_token = Api(dongle_id).get_token()
|
||||
ws = create_connection(remote_ws_uri,
|
||||
cookie="jwt=" + identity_token,
|
||||
@@ -532,12 +532,12 @@ def getPublicKey() -> str | None:
|
||||
|
||||
@dispatcher.add_method
|
||||
def getSshAuthorizedKeys() -> str:
|
||||
return Params().get("GithubSshKeys", encoding='utf8') or ''
|
||||
return cast(str, Params().get("GithubSshKeys", default=""))
|
||||
|
||||
|
||||
@dispatcher.add_method
|
||||
def getGithubUsername() -> str:
|
||||
return Params().get("GithubUsername", encoding='utf8') or ''
|
||||
return cast(str, Params().get("GithubUsername", default=""))
|
||||
|
||||
@dispatcher.add_method
|
||||
def getSimInfo():
|
||||
@@ -815,7 +815,7 @@ def main(exit_event: threading.Event = None):
|
||||
cloudlog.exception("failed to set core affinity")
|
||||
|
||||
params = Params()
|
||||
dongle_id = params.get("DongleId", encoding='utf-8')
|
||||
dongle_id = params.get("DongleId")
|
||||
UploadQueueCache.initialize(upload_queue)
|
||||
|
||||
ws_uri = ATHENA_HOST + "/ws/v2/" + dongle_id
|
||||
|
||||
@@ -14,7 +14,7 @@ ATHENA_MGR_PID_PARAM = "AthenadPid"
|
||||
|
||||
def main():
|
||||
params = Params()
|
||||
dongle_id = params.get("DongleId").decode('utf-8')
|
||||
dongle_id = params.get("DongleId")
|
||||
build_metadata = get_build_metadata()
|
||||
|
||||
cloudlog.bind_global(dongle_id=dongle_id,
|
||||
|
||||
@@ -17,7 +17,7 @@ from openpilot.common.swaglog import cloudlog
|
||||
UNREGISTERED_DONGLE_ID = "UnregisteredDevice"
|
||||
|
||||
def is_registered_device() -> bool:
|
||||
dongle = Params().get("DongleId", encoding='utf-8')
|
||||
dongle = Params().get("DongleId")
|
||||
return dongle not in (None, UNREGISTERED_DONGLE_ID)
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ def register(show_spinner=False) -> str | None:
|
||||
"""
|
||||
params = Params()
|
||||
|
||||
dongle_id: str | None = params.get("DongleId", encoding='utf8')
|
||||
dongle_id: str | None = params.get("DongleId")
|
||||
if dongle_id is None and Path(Paths.persist_root()+"/comma/dongle_id").is_file():
|
||||
# not all devices will have this; added early in comma 3X production (2/28/24)
|
||||
with open(Paths.persist_root()+"/comma/dongle_id") as f:
|
||||
|
||||
@@ -28,7 +28,7 @@ class TestAthenadPing:
|
||||
exit_event: threading.Event
|
||||
|
||||
def _get_ping_time(self) -> str | None:
|
||||
return cast(str | None, self.params.get("LastAthenaPingTime", encoding="utf-8"))
|
||||
return cast(str | None, self.params.get("LastAthenaPingTime"))
|
||||
|
||||
def _clear_ping_time(self) -> None:
|
||||
self.params.remove("LastAthenaPingTime")
|
||||
@@ -42,7 +42,7 @@ class TestAthenadPing:
|
||||
|
||||
def setup_method(self) -> None:
|
||||
self.params = Params()
|
||||
self.dongle_id = self.params.get("DongleId", encoding="utf-8")
|
||||
self.dongle_id = self.params.get("DongleId")
|
||||
|
||||
wifi_radio(True)
|
||||
self._clear_ping_time()
|
||||
|
||||
@@ -49,7 +49,7 @@ class TestRegistration:
|
||||
dongle = register()
|
||||
assert m.call_count == 0
|
||||
assert dongle == UNREGISTERED_DONGLE_ID
|
||||
assert self.params.get("DongleId", encoding='utf-8') == dongle
|
||||
assert self.params.get("DongleId") == dongle
|
||||
|
||||
def test_missing_cache(self, mocker):
|
||||
# keys exist but no dongle id
|
||||
@@ -63,7 +63,7 @@ class TestRegistration:
|
||||
# call again, shouldn't hit the API this time
|
||||
assert register() == dongle
|
||||
assert m.call_count == 1
|
||||
assert self.params.get("DongleId", encoding='utf-8') == dongle
|
||||
assert self.params.get("DongleId") == dongle
|
||||
|
||||
def test_unregistered(self, mocker):
|
||||
# keys exist, but unregistered
|
||||
@@ -73,4 +73,4 @@ class TestRegistration:
|
||||
dongle = register()
|
||||
assert m.call_count == 1
|
||||
assert dongle == UNREGISTERED_DONGLE_ID
|
||||
assert self.params.get("DongleId", encoding='utf-8') == dongle
|
||||
assert self.params.get("DongleId") == dongle
|
||||
|
||||
@@ -400,7 +400,7 @@ def hardware_thread(end_event, hw_queue) -> None:
|
||||
|
||||
last_ping = params.get("LastAthenaPingTime")
|
||||
if last_ping is not None:
|
||||
msg.deviceState.lastAthenaPingTime = int(last_ping)
|
||||
msg.deviceState.lastAthenaPingTime = last_ping
|
||||
|
||||
msg.deviceState.thermalStatus = thermal_status
|
||||
pm.send("deviceState", msg)
|
||||
|
||||
@@ -88,7 +88,7 @@ class Uploader:
|
||||
self.immediate_priority = {"qlog": 0, "qlog.zst": 0, "qcamera.ts": 1}
|
||||
|
||||
def list_upload_files(self, metered: bool) -> Iterator[tuple[str, str, str]]:
|
||||
r = self.params.get("AthenadRecentlyViewedRoutes", encoding="utf8")
|
||||
r = self.params.get("AthenadRecentlyViewedRoutes")
|
||||
requested_routes = [] if r is None else [route for route in r.split(",") if route]
|
||||
|
||||
for logdir in listdir_by_creation(self.root):
|
||||
@@ -238,7 +238,7 @@ def main(exit_event: threading.Event = None) -> None:
|
||||
clear_locks(Paths.log_root())
|
||||
|
||||
params = Params()
|
||||
dongle_id = params.get("DongleId", encoding='utf8')
|
||||
dongle_id = params.get("DongleId")
|
||||
|
||||
if dongle_id is None:
|
||||
cloudlog.info("uploader missing dongle_id")
|
||||
|
||||
@@ -112,7 +112,7 @@ def manager_thread() -> None:
|
||||
params = Params()
|
||||
|
||||
ignore: list[str] = []
|
||||
if params.get("DongleId", encoding='utf8') in (None, UNREGISTERED_DONGLE_ID):
|
||||
if params.get("DongleId") in (None, UNREGISTERED_DONGLE_ID):
|
||||
ignore += ["manage_athenad", "uploader"]
|
||||
if os.getenv("NOBOARD") is not None:
|
||||
ignore.append("pandad")
|
||||
|
||||
@@ -251,7 +251,7 @@ class DaemonProcess(ManagerProcess):
|
||||
if self.params is None:
|
||||
self.params = Params()
|
||||
|
||||
pid = self.params.get(self.param_name, encoding='utf-8')
|
||||
pid = self.params.get(self.param_name)
|
||||
if pid is not None:
|
||||
try:
|
||||
os.kill(int(pid), 0)
|
||||
|
||||
+1
-1
@@ -49,7 +49,7 @@ def init(project: SentryProject) -> bool:
|
||||
return False
|
||||
|
||||
env = "release" if build_metadata.tested_channel else "master"
|
||||
dongle_id = Params().get("DongleId", encoding='utf-8')
|
||||
dongle_id = Params().get("DongleId")
|
||||
|
||||
integrations = []
|
||||
if project == SentryProject.SELFDRIVE:
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ class StatLog:
|
||||
|
||||
|
||||
def main() -> NoReturn:
|
||||
dongle_id = Params().get("DongleId", encoding='utf-8')
|
||||
dongle_id = Params().get("DongleId")
|
||||
def get_influxdb_line(measurement: str, value: float | dict[str, float], timestamp: datetime, tags: dict) -> str:
|
||||
res = f"{measurement}"
|
||||
for k, v in tags.items():
|
||||
|
||||
@@ -41,7 +41,7 @@ def add_ubx_checksum(msg: bytes) -> bytes:
|
||||
B = (B + A) % 256
|
||||
return msg + bytes([A, B])
|
||||
|
||||
def get_assistnow_messages(token: bytes) -> list[bytes]:
|
||||
def get_assistnow_messages(token: str) -> list[bytes]:
|
||||
# make request
|
||||
# TODO: implement adding the last known location
|
||||
r = requests.get("https://online-live2.services.u-blox.com/GetOnlineData.ashx", params=urllib.parse.urlencode({
|
||||
|
||||
@@ -91,7 +91,7 @@ class WifiManager:
|
||||
# Set tethering ssid as "weedle" + first 4 characters of a dongle id
|
||||
self._tethering_ssid = "weedle"
|
||||
if Params is not None:
|
||||
dongle_id = Params().get("DongleId", encoding="utf-8")
|
||||
dongle_id = Params().get("DongleId")
|
||||
if dongle_id:
|
||||
self._tethering_ssid += "-" + dongle_id[:4]
|
||||
self.running: bool = True
|
||||
|
||||
@@ -132,8 +132,8 @@ class TestBaseUpdate:
|
||||
|
||||
class ParamsBaseUpdateTest(TestBaseUpdate):
|
||||
def _test_finalized_update(self, branch, version, agnos_version, release_notes):
|
||||
assert self.params.get("UpdaterNewDescription", encoding="utf-8").startswith(f"{version} / {branch}")
|
||||
assert self.params.get("UpdaterNewReleaseNotes", encoding="utf-8") == f"{release_notes}\n"
|
||||
assert self.params.get("UpdaterNewDescription").startswith(f"{version} / {branch}")
|
||||
assert self.params.get("UpdaterNewReleaseNotes") == f"{release_notes}\n"
|
||||
super()._test_finalized_update(branch, version, agnos_version, release_notes)
|
||||
|
||||
def send_check_for_updates_signal(self, updated: ManagerProcess):
|
||||
@@ -143,16 +143,16 @@ class ParamsBaseUpdateTest(TestBaseUpdate):
|
||||
updated.signal(signal.SIGHUP.value)
|
||||
|
||||
def _test_params(self, branch, fetch_available, update_available):
|
||||
assert self.params.get("UpdaterTargetBranch", encoding="utf-8") == branch
|
||||
assert self.params.get("UpdaterTargetBranch") == branch
|
||||
assert self.params.get_bool("UpdaterFetchAvailable") == fetch_available
|
||||
assert self.params.get_bool("UpdateAvailable") == update_available
|
||||
|
||||
def wait_for_idle(self):
|
||||
self.wait_for_condition(lambda: self.params.get("UpdaterState", encoding="utf-8") == "idle")
|
||||
self.wait_for_condition(lambda: self.params.get("UpdaterState") == "idle")
|
||||
|
||||
def wait_for_failed(self):
|
||||
self.wait_for_condition(lambda: self.params.get("UpdateFailedCount", encoding="utf-8") is not None and \
|
||||
self.params.get("UpdateFailedCount", encoding="utf-8") > 0)
|
||||
self.wait_for_condition(lambda: self.params.get("UpdateFailedCount") is not None and \
|
||||
self.params.get("UpdateFailedCount") > 0)
|
||||
|
||||
def wait_for_fetch_available(self):
|
||||
self.wait_for_condition(lambda: self.params.get_bool("UpdaterFetchAvailable"))
|
||||
|
||||
@@ -234,7 +234,7 @@ class Updater:
|
||||
|
||||
@property
|
||||
def target_branch(self) -> str:
|
||||
b: str | None = self.params.get("UpdaterTargetBranch", encoding='utf-8')
|
||||
b: str | None = self.params.get("UpdaterTargetBranch")
|
||||
if b is None:
|
||||
b = self.get_branch(BASEDIR)
|
||||
return b
|
||||
@@ -275,7 +275,7 @@ class Updater:
|
||||
if update_success:
|
||||
write_time_to_param(self.params, "LastUpdateTime")
|
||||
else:
|
||||
t = self.params.get("LastUpdateTime", encoding="utf8")
|
||||
t = self.params.get("LastUpdateTime")
|
||||
if t is not None:
|
||||
last_update = t
|
||||
|
||||
@@ -420,7 +420,7 @@ def main() -> None:
|
||||
if Path(os.path.join(STAGING_ROOT, "old_openpilot")).is_dir():
|
||||
cloudlog.event("update installed")
|
||||
|
||||
if not params.get("InstallDate", encoding="utf-8"):
|
||||
if not params.get("InstallDate"):
|
||||
t = datetime.datetime.now(datetime.UTC).replace(tzinfo=None).isoformat()
|
||||
params.put("InstallDate", t.encode('utf8'))
|
||||
|
||||
@@ -460,7 +460,7 @@ def main() -> None:
|
||||
updater.check_for_update()
|
||||
|
||||
# download update
|
||||
last_fetch = params.get("UpdaterLastFetchTime", encoding="utf8")
|
||||
last_fetch = params.get("UpdaterLastFetchTime")
|
||||
timed_out = last_fetch is None or (datetime.datetime.now(datetime.UTC).replace(tzinfo=None) - last_fetch > datetime.timedelta(days=3))
|
||||
user_requested_fetch = wait_helper.user_request == UserRequest.FETCH
|
||||
if params.get_bool("NetworkMetered") and not timed_out and not user_requested_fetch:
|
||||
|
||||
+2
-2
@@ -15,8 +15,8 @@ TESTED_BRANCHES = RELEASE_BRANCHES + ['devel', 'devel-staging', 'nightly-dev']
|
||||
|
||||
BUILD_METADATA_FILENAME = "build.json"
|
||||
|
||||
training_version: bytes = b"0.2.0"
|
||||
terms_version: bytes = b"2"
|
||||
training_version: str = "0.2.0"
|
||||
terms_version: str = "2"
|
||||
|
||||
|
||||
def get_version(path: str = BASEDIR) -> str:
|
||||
|
||||
Reference in New Issue
Block a user