fix: odometer sync is Pi→Server only — portal displays read-only value from DB

This commit is contained in:
Mathieu Moran
2026-08-11 22:14:46 -04:00
parent 7de8948e08
commit d35cea367f
4 changed files with 29 additions and 16 deletions
+3 -11
View File
@@ -42,7 +42,8 @@ def update_device_config(device_id, data):
car_model = data.get("car_model", "").strip() if "car_model" in data else None
device_name = data.get("device_name", "").strip() if "device_name" in data else None
avatar_path = data.get("avatar_path", "").strip() if "avatar_path" in data else None
odometer_baseline = data.get("odometer_baseline") if "odometer_baseline" in data else None
# odometer_baseline is NOT accepted here — it's Pi→Server only,
# handled directly in the /api/device-config/push endpoint.
if owner_name is not None and len(owner_name) > 100:
errors["owner_name"] = "Owner name must be 1-100 characters."
@@ -52,19 +53,12 @@ def update_device_config(device_id, data):
errors["device_name"] = "Device name must be 1-100 characters."
if avatar_path is not None and len(avatar_path) > 255:
errors["avatar_path"] = "Avatar path must be 1-255 characters."
if odometer_baseline is not None:
try:
odometer_baseline = float(odometer_baseline)
if odometer_baseline < 0 or odometer_baseline > 999999:
errors["odometer_baseline"] = "Must be between 0 and 999,999 km."
except (TypeError, ValueError):
errors["odometer_baseline"] = "Must be a number."
if errors:
return False, errors
with db.get_cursor(commit=True) as cur:
changed = owner_name is not None or car_model is not None or device_name is not None or avatar_path is not None or odometer_baseline is not None
changed = owner_name is not None or car_model is not None or device_name is not None or avatar_path is not None
if changed:
cur.execute(
"UPDATE devices SET config_version = config_version + 1, config_updated_at = now() WHERE id = %s",
@@ -79,7 +73,5 @@ def update_device_config(device_id, data):
cur.execute("UPDATE devices SET device_name = %s WHERE id = %s", (device_name, device_id))
if avatar_path is not None:
cur.execute("UPDATE devices SET avatar_path = %s WHERE id = %s", (avatar_path, device_id))
if odometer_baseline is not None:
cur.execute("UPDATE devices SET odometer_baseline = %s WHERE id = %s", (odometer_baseline, device_id))
return True, {}