Skip to content

fix: calendar feed crash + fuel-to-fill consumption + station edit link (#168, #169, #170)#171

Merged
dannymcc merged 2 commits into
mainfrom
dev
May 3, 2026
Merged

fix: calendar feed crash + fuel-to-fill consumption + station edit link (#168, #169, #170)#171
dannymcc merged 2 commits into
mainfrom
dev

Conversation

@dannymcc
Copy link
Copy Markdown
Owner

@dannymcc dannymcc commented May 3, 2026

Summary

  • Bug: /api/calendar/feed crashes in May 0.22.1 because MaintenanceSchedule.next_due_mileage does not exist #168 — `/api/calendar/feed` crashed with `AttributeError: 'MaintenanceSchedule' object has no attribute 'next_due_mileage'`. The column is actually `next_due_odometer`. Same bad attribute name was referenced in the Home Assistant alerts route, and calendar code also called `vehicle.unit_distance` (which doesn't exist) — switched to `get_effective_odometer_unit()`.
  • Consumption miscalculation in case of non full fill-up? #169 — full-tank consumption only counted the current fill's volume instead of every litre poured between the previous full tank and this one. With partials between fulls, the figure was arbitrarily low (astrmn: 1371 km, 19.67 + 12.71 + 53.80 = 86.18 L, expected 6.29 L/100km, getting ~3.9). `Vehicle.get_average_consumption` had the same shape of bug. Both now use proper fill-to-fill totals and return `None` when an intervening log is flagged `is_missed`.
  • Adding Gas Station after fuel log - Statistics not updating #170 — linking a station to an existing log via edit didn't bump the station's `times_used` counter, and changing the station on a log that already had one left the price-history row pointing at the old station. The edit handler's price-history reconciliation now covers create + first link, swap, and clear cases consistently.

Test plan

  • `pytest tests/test_fuel.py::TestPartialFillConsumption` — 3 new tests pass
  • `pytest tests/test_fuel.py::TestPriceHistorySync` — 1 new test pass alongside existing 4
  • Full `pytest tests/` — 563 passed

dannymcc added 2 commits May 3, 2026 18:05
#168 — `/api/calendar/feed` and the Home Assistant alerts route both
referenced `MaintenanceSchedule.next_due_mileage`, which doesn't exist
(the column is `next_due_odometer`). Calendar also called
`vehicle.unit_distance` instead of `vehicle.get_effective_odometer_unit()`,
so even after fixing the column the request would have failed for
vehicles with a custom odometer unit.

#169 — full-tank consumption only counted the volume of the current
fill instead of summing every litre poured between the previous full
tank and this one. With partial fills in between, the result was
arbitrarily low (astrmn's case: 53.80 L over 1371 km reported as
~3.9 L/100km when the real fill-to-fill figure is 6.29 L/100km).
`Vehicle.get_average_consumption` had the same shape of bug — only
full-tank logs counted toward the total. Both now sum every fill in
the range and bail out (return None) when any intervening log is
flagged `is_missed`, so we don't show a confidently wrong number.

- Bump APP_VERSION to 0.22.2
- New regression tests for the partial-fill and missed-fill cases
Astrmn's flow — log a fill-up first, create the station afterwards,
then edit the log to attach the station — left both stats stale: the
station's `times_used` counter never moved, and when the user *did*
later swap the station on a log that already had one, the price-history
row stayed pointed at the old station.

The fix consolidates the price-history reconciliation in the edit
handler: create + bump on first link, swap station_id + bump on a
station change, delete on a price clear. Now the "cheapest fuel" list
and "Used Nx" counter both reflect the current state of every log.

- New regression test for the issue #170 scenario
@dannymcc dannymcc changed the title fix: calendar feed crash + fuel-to-fill consumption (#168, #169) fix: calendar feed crash + fuel-to-fill consumption + station edit link (#168, #169, #170) May 3, 2026
@dannymcc dannymcc merged commit 869bef8 into main May 3, 2026
2 checks passed
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