Add offline and ntfy alerts

Co-authored-by: Copilot <[email protected]>
This commit is contained in:
Mathieu Moran
2026-08-09 20:28:42 -04:00
co-authored by Copilot
parent 8b664667e5
commit 96332adab6
12 changed files with 1098 additions and 21 deletions
+17 -1
View File
@@ -22,6 +22,8 @@ throttle_position = None
mil_on = None
dtc_codes = []
odometer = None
mil_updated_at = None
dtc_updated_at = None
class OBD:
@@ -251,6 +253,18 @@ def obd_connection():
_emit_disconnected()
def get_fresh_mil(max_age=SENSOR_POLL_INTERVAL * 3):
if mil_updated_at is None or time.monotonic() - mil_updated_at > max_age:
return None
return mil_on
def get_fresh_dtc_codes(max_age=SENSOR_POLL_INTERVAL * 3):
if dtc_updated_at is None or time.monotonic() - dtc_updated_at > max_age:
return []
return list(dtc_codes)
def obd_speed():
global speed, speed_updated_at
with obd_speed_lock:
@@ -298,7 +312,7 @@ def _quantity_value(command, unit=None):
def _poll_diagnostics():
global coolant_temp, fuel_level, throttle_position
global mil_on, dtc_codes, odometer
global mil_on, dtc_codes, odometer, mil_updated_at, dtc_updated_at
coolant_temp = _quantity_value(obd.commands.COOLANT_TEMP, "degC")
fuel_level = _quantity_value(obd.commands.FUEL_LEVEL, "percent")
@@ -307,6 +321,7 @@ def _poll_diagnostics():
status_response = _query(obd.commands.STATUS)
if status_response is not None and not status_response.is_null():
mil_on = bool(status_response.value.MIL)
mil_updated_at = time.monotonic()
app_events.socketio.emit(
"obd_mil",
{"on": mil_on, "dtc_count": status_response.value.DTC_count},
@@ -318,6 +333,7 @@ def _poll_diagnostics():
{"code": code, "description": description}
for code, description in dtc_response.value
]
dtc_updated_at = time.monotonic()
app_events.socketio.emit("obd_dtc", dtc_codes)
odometer_response = _query(ODOMETER_COMMAND, force=True)