Fix slow OBD value load on dashboard (BUG-19)

This commit is contained in:
Mathieu Moran
2026-08-13 16:57:16 -04:00
parent e873db918d
commit c2462356e1
5 changed files with 141 additions and 4 deletions
+42
View File
@@ -271,9 +271,51 @@ def get_fresh_speed(max_age=5):
return speed
def emit_current_state():
"""Push the current OBD values to a newly connected dashboard.
The polling threads only emit on their next tick, so a freshly loaded
page would otherwise sit on "—" until then. Emitting a snapshot here makes
the cards fill immediately on connect/reconnect instead of waiting for the
next poll cycle (or a reconnect/probe round-trip).
"""
connected = _is_car_connected()
app_events.socketio.emit(
"obd_status", obd_status[1] if connected else obd_status[0]
)
if connected:
app_events.socketio.emit("obd_speed", get_speedtime())
app_events.socketio.emit("obd_rpm", rpm if rpm is not None else "-")
app_events.socketio.emit(
"obd_coolant_temp",
coolant_temp if coolant_temp is not None else "-",
)
app_events.socketio.emit(
"obd_fuel_level",
fuel_level if fuel_level is not None else "-",
)
app_events.socketio.emit(
"obd_throttle",
throttle_position if throttle_position is not None else "-",
)
if mil_on is not None:
app_events.socketio.emit(
"obd_mil", {"on": mil_on, "dtc_count": len(dtc_codes)}
)
if dtc_codes:
app_events.socketio.emit("obd_dtc", dtc_codes)
else:
app_events.socketio.emit("obd_speed", "-")
app_events.socketio.emit("obd_rpm", "-")
app_events.socketio.emit("obd_coolant_temp", "-")
app_events.socketio.emit("obd_fuel_level", "-")
app_events.socketio.emit("obd_throttle", "-")
def obd_connection():
"""Emit current state for a newly connected browser and ensure OBD is running."""
start_obd()
emit_current_state()
def _persist_car_connected():