feat: odometer baseline syncs to server — push on save, pull on sync, +/api/device-config/push endpoint
This commit is contained in:
@@ -220,4 +220,29 @@ def update_settings(body):
|
||||
settings["alert_ntfy_token"] = ntfy_token
|
||||
|
||||
app_sql.set_settings(settings)
|
||||
|
||||
# Push odometer_baseline to server if configured and non-zero
|
||||
if values["odometer_baseline"] is not None and values["odometer_baseline"] > 0:
|
||||
_push_odometer_to_server(values["odometer_baseline"])
|
||||
|
||||
return {}
|
||||
|
||||
|
||||
def _push_odometer_to_server(baseline):
|
||||
try:
|
||||
from . import app_upload
|
||||
creds = app_upload._credentials()
|
||||
if not creds["server_url"] or not creds["device_name"] or not creds["api_key"]:
|
||||
return
|
||||
import requests
|
||||
requests.post(
|
||||
f"{creds['server_url']}/api/device-config/push",
|
||||
headers={
|
||||
"X-Device-Name": creds["device_name"],
|
||||
"X-Api-Key": creds["api_key"],
|
||||
},
|
||||
json={"odometer_baseline": baseline},
|
||||
timeout=5,
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user