fix: odometer sync is Pi→Server only — portal displays read-only value from DB
This commit is contained in:
@@ -788,8 +788,27 @@ def api_device_config_push():
|
||||
|
||||
Pi pushes local config changes to server. Accepts a partial update:
|
||||
any of owner_name, car_model, device_name, avatar_path, odometer_baseline.
|
||||
odometer_baseline is Pi→Server only — the portal cannot edit it.
|
||||
"""
|
||||
body = request.get_json(silent=True) or {}
|
||||
|
||||
# Handle odometer_baseline separately — Pi→Server only.
|
||||
odometer = body.pop("odometer_baseline", None)
|
||||
if odometer is not None:
|
||||
try:
|
||||
odometer = float(odometer)
|
||||
if odometer < 0 or odometer > 999999:
|
||||
return jsonify(error="Invalid device config.",
|
||||
fields={"odometer_baseline": "Must be between 0 and 999,999 km."}), 400
|
||||
except (TypeError, ValueError):
|
||||
return jsonify(error="Invalid device config.",
|
||||
fields={"odometer_baseline": "Must be a number."}), 400
|
||||
with db.get_cursor(commit=True) as cur:
|
||||
cur.execute(
|
||||
"UPDATE devices SET odometer_baseline = %s, config_version = config_version + 1, config_updated_at = now() WHERE id = %s",
|
||||
(odometer, g.device_id),
|
||||
)
|
||||
|
||||
success, errors = device_config.update_device_config(g.device_id, body)
|
||||
if not success:
|
||||
return jsonify(error="Invalid device config.", fields=errors), 400
|
||||
|
||||
Reference in New Issue
Block a user