mirror of
https://github.com/dragonpilot/dragonpilot.git
synced 2026-06-24 23:42:05 +08:00
params: make python and c++ API match (#25573)
* params: make python and c++ API match * few more
This commit is contained in:
@@ -90,7 +90,7 @@ cdef class Params:
|
||||
with nogil:
|
||||
self.p.putBool(k, val)
|
||||
|
||||
def delete(self, key):
|
||||
def remove(self, key):
|
||||
cdef string k = self.check_key(key)
|
||||
with nogil:
|
||||
self.p.remove(k)
|
||||
|
||||
@@ -59,13 +59,13 @@ class TestParams(unittest.TestCase):
|
||||
with self.assertRaises(UnknownKeyName):
|
||||
self.params.put_bool("swag", True)
|
||||
|
||||
def test_delete_not_there(self):
|
||||
def test_remove_not_there(self):
|
||||
assert self.params.get("CarParams") is None
|
||||
self.params.delete("CarParams")
|
||||
self.params.remove("CarParams")
|
||||
assert self.params.get("CarParams") is None
|
||||
|
||||
def test_get_bool(self):
|
||||
self.params.delete("IsMetric")
|
||||
self.params.remove("IsMetric")
|
||||
self.assertFalse(self.params.get_bool("IsMetric"))
|
||||
|
||||
self.params.put_bool("IsMetric", True)
|
||||
|
||||
@@ -739,14 +739,14 @@ def main():
|
||||
break
|
||||
except (ConnectionError, TimeoutError, WebSocketException):
|
||||
conn_retries += 1
|
||||
params.delete("LastAthenaPingTime")
|
||||
params.remove("LastAthenaPingTime")
|
||||
except socket.timeout:
|
||||
params.delete("LastAthenaPingTime")
|
||||
params.remove("LastAthenaPingTime")
|
||||
except Exception:
|
||||
cloudlog.exception("athenad.main.exception")
|
||||
|
||||
conn_retries += 1
|
||||
params.delete("LastAthenaPingTime")
|
||||
params.remove("LastAthenaPingTime")
|
||||
|
||||
time.sleep(backoff(conn_retries))
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ def main():
|
||||
except Exception:
|
||||
cloudlog.exception("manage_athenad.exception")
|
||||
finally:
|
||||
params.delete(ATHENA_MGR_PID_PARAM)
|
||||
params.remove(ATHENA_MGR_PID_PARAM)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -83,7 +83,7 @@ def main() -> NoReturn:
|
||||
|
||||
while True:
|
||||
try:
|
||||
params.delete("PandaSignatures")
|
||||
params.remove("PandaSignatures")
|
||||
|
||||
# Flash all Pandas in DFU mode
|
||||
for p in PandaDFU.list():
|
||||
|
||||
@@ -22,7 +22,7 @@ def set_offroad_alert(alert: str, show_alert: bool, extra_text: Optional[str] =
|
||||
a['text'] += extra_text
|
||||
Params().put(alert, json.dumps(a))
|
||||
else:
|
||||
Params().delete(alert)
|
||||
Params().remove(alert)
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -65,7 +65,7 @@ class TestLaikad(unittest.TestCase):
|
||||
cls.first_gps_time = first_gps_time
|
||||
|
||||
def setUp(self):
|
||||
Params().delete(EPHEMERIS_CACHE)
|
||||
Params().remove(EPHEMERIS_CACHE)
|
||||
|
||||
def test_fetch_orbits_non_blocking(self):
|
||||
gpstime = GPSTime.from_datetime(datetime(2021, month=3, day=1))
|
||||
@@ -226,7 +226,7 @@ class TestLaikad(unittest.TestCase):
|
||||
# Test cache with no ephemeris
|
||||
laikad.cache_ephemeris(t=GPSTime(0, 0))
|
||||
wait_for_cache()
|
||||
Params().delete(EPHEMERIS_CACHE)
|
||||
Params().remove(EPHEMERIS_CACHE)
|
||||
|
||||
laikad.astro_dog.get_navs(self.first_gps_time)
|
||||
laikad.fetch_orbits(self.first_gps_time, block=True)
|
||||
|
||||
@@ -62,7 +62,7 @@ class TestLocationdProc(unittest.TestCase):
|
||||
|
||||
def test_params_gps(self):
|
||||
# first reset params
|
||||
Params().delete('LastGPSPosition')
|
||||
Params().remove('LastGPSPosition')
|
||||
|
||||
self.lat = 30 + (random.random() * 10.0)
|
||||
self.lon = -70 + (random.random() * 10.0)
|
||||
|
||||
@@ -49,7 +49,7 @@ def manager_init() -> None:
|
||||
params.put_bool("RecordFront", True)
|
||||
|
||||
if not params.get_bool("DisableRadar_Allow"):
|
||||
params.delete("DisableRadar")
|
||||
params.remove("DisableRadar")
|
||||
|
||||
# set unset params
|
||||
for k, v in default_params:
|
||||
|
||||
@@ -236,7 +236,7 @@ class RouteEngine:
|
||||
self.recompute_countdown = 0
|
||||
else:
|
||||
cloudlog.warning("Destination reached")
|
||||
Params().delete("NavDestination")
|
||||
Params().remove("NavDestination")
|
||||
|
||||
# Clear route if driving away from destination
|
||||
dist = self.nav_destination.distance_to(self.last_position)
|
||||
|
||||
@@ -418,7 +418,7 @@ def setup_env(simulation=False, CP=None, cfg=None, controlsState=None):
|
||||
if controlsState is not None:
|
||||
params.put("ReplayControlsState", controlsState.as_builder().to_bytes())
|
||||
else:
|
||||
params.delete("ReplayControlsState")
|
||||
params.remove("ReplayControlsState")
|
||||
|
||||
# Regen or python process
|
||||
if CP is not None:
|
||||
|
||||
@@ -113,7 +113,7 @@ class TestUpdated(unittest.TestCase):
|
||||
|
||||
def _wait_for_update(self, timeout=30, clear_param=False):
|
||||
if clear_param:
|
||||
self.params.delete("LastUpdateTime")
|
||||
self.params.remove("LastUpdateTime")
|
||||
|
||||
self._update_now()
|
||||
t = self._read_param("LastUpdateTime", timeout=timeout)
|
||||
@@ -166,7 +166,7 @@ class TestUpdated(unittest.TestCase):
|
||||
last_update_time = datetime.datetime.fromisoformat(t)
|
||||
td = datetime.datetime.utcnow() - last_update_time
|
||||
self.assertLess(td.total_seconds(), 10)
|
||||
self.params.delete("LastUpdateTime")
|
||||
self.params.remove("LastUpdateTime")
|
||||
|
||||
# wait a bit for the rest of the params to be written
|
||||
time.sleep(0.1)
|
||||
@@ -232,7 +232,7 @@ class TestUpdated(unittest.TestCase):
|
||||
|
||||
# run for a cycle with no update
|
||||
self._wait_for_update(clear_param=True)
|
||||
self.params.delete("LastUpdateTime")
|
||||
self.params.remove("LastUpdateTime")
|
||||
first_mtime = os.path.getmtime(overlay_init_fn)
|
||||
|
||||
# touch a file in the basedir
|
||||
|
||||
@@ -31,8 +31,8 @@ def pm_patch(name, value, constant=False):
|
||||
class TestPowerMonitoring(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# Clear stored capacity before each test
|
||||
params.delete("CarBatteryCapacity")
|
||||
params.delete("DisablePowerDown")
|
||||
params.remove("CarBatteryCapacity")
|
||||
params.remove("DisablePowerDown")
|
||||
|
||||
def mock_peripheralState(self, hw_type, car_voltage=12):
|
||||
ps = messaging.new_message('peripheralState').peripheralState
|
||||
|
||||
@@ -116,7 +116,7 @@ def set_params(new_version: bool, failed_count: int, exception: Optional[str]) -
|
||||
pass
|
||||
|
||||
if exception is None:
|
||||
params.delete("LastUpdateException")
|
||||
params.remove("LastUpdateException")
|
||||
else:
|
||||
params.put("LastUpdateException", exception)
|
||||
|
||||
|
||||
@@ -91,7 +91,7 @@ def snapshot():
|
||||
subprocess.check_call(["pgrep", "camerad"])
|
||||
print("Camerad already running")
|
||||
params.put_bool("IsTakingSnapshot", False)
|
||||
params.delete("Offroad_IsTakingSnapshot")
|
||||
params.remove("Offroad_IsTakingSnapshot")
|
||||
return None, None
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
+1
-1
@@ -548,4 +548,4 @@ if __name__ == "__main__":
|
||||
finally:
|
||||
# Try cleaning up the wide camera param
|
||||
# in case users want to use replay after
|
||||
Params().delete("WideCameraOnly")
|
||||
Params().remove("WideCameraOnly")
|
||||
|
||||
Reference in New Issue
Block a user