Skip to content

fix: recover last trip distance when the board wipes it on remote power-cycle - #10

Merged
jmdevita merged 1 commit into
mainfrom
fix/recover-last-trip-distance
Jun 25, 2026
Merged

jmdevita merged 1 commit into
mainfrom
fix/recover-last-trip-distance

Conversation

@jmdevita

Copy link
Copy Markdown
Owner

Problem

The board reports per-trip distance via DP5 mileage_once, but the board wipes DP5 to 0 when the remote is power-cycled — e.g. turning it off then back on to "sync" once you're home in range. That blanked a just-completed ride's distance on the dashboard (shows 0.00 mi).

Fix

Trip-distance recovery now lives in the coordinator, the only place with access to both the previous and current read. A new EboardSnapshot.trip_distance_km10 carries an effective last-trip value computed each read:

  • DP5 nonzero → trust it as-is.
  • DP5 == 0 and the cumulative odometer (DP12) advanced since the last read → a ride happened between reads, so use the odometer delta.
  • DP5 == 0 and the odometer is flat → a reconnect/sync with no new riding; keep the last known trip instead of overwriting it with 0.

The trip_distance sensor now reads the recovered value instead of DP5 directly.

Notes / known limits

  • The first read immediately after an HA restart has no in-memory previous snapshot, so a sync read at that exact moment can still fall through to 0 (self-corrects on the next ride). Documented, deliberately not addressed — fixing it would mean persisting coordinator state backwards from the entity.
  • Last trip time (DP6 ridetime_once) is not recoverable the same way: there is no cumulative ride-time counter to derive a delta from, and the board reports DP6 inconsistently. Left as-is.

Testing

  • ruff check custom_components — clean
  • pytest -q — 28 passed (pure suite, no hardware/HA)

Bumps manifest to 0.3.1.

…er-cycle

The board's DP5 (mileage_once) is wiped to 0 when the remote is power-cycled
(e.g. turning it off then back on to sync at home), which blanked a just-completed
ride on the dashboard.

Recovery now lives in the coordinator, the only place that sees both the previous
and current read. When DP5 reads 0 the effective last-trip distance is derived from
the cumulative odometer (DP12) delta if the odometer advanced between reads, and
otherwise the last known trip is preserved instead of being overwritten with 0
(the flat-odometer reconnect/sync case). A nonzero DP5 is always trusted as-is.

Also bump manifest to 0.3.1.
@jmdevita
jmdevita merged commit ba982a2 into main Jun 25, 2026
10 checks passed
@jmdevita
jmdevita deleted the fix/recover-last-trip-distance branch June 25, 2026 03:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant