Skip to content

feat(monitor): combined fuel+TPMS monitoring with SQLite history - #6

Merged
tclancy merged 3 commits into
mainfrom
claude/tpms-fuel-sqlite-4-5
Apr 16, 2026
Merged

feat(monitor): combined fuel+TPMS monitoring with SQLite history#6
tclancy merged 3 commits into
mainfrom
claude/tpms-fuel-sqlite-4-5

Conversation

@metaframework-dispatch-bot

Copy link
Copy Markdown

Summary

  • Issue Research: Tire Pressue #4 (TPMS): Per-wheel tire pressure warning lamp monitoring with temperature correlation. The Bluelink API only provides boolean lamp states (no raw PSI) — this monitors off→on transitions per wheel plus the global all flag, deduplicates alerts, and re-arms when lamps clear.
  • Issue Research: Fuel Usage #5 (Fuel history): Fill-up detection (range rise >20 miles), odometer read at fill-up events for mpg tracking.
  • Combined: One vehicle.status() call drives both checks; temperature fetched from Open-Meteo (free, no API key) and logged alongside every reading.
  • SQLite: Three normalized tables (checks, tpms_readings, alerts) via better-sqlite3 in state/vehicle-monitor.db.

New files

File Purpose
src/vehicle-db.ts SQLite schema + typed insert/query methods
src/monitor-helpers.ts Pure functions (temp fetch, TPMS logic) — testable without API
monitor.ts Combined monitoring entry point (replaces monitor-fuel.ts for new runs)

Key design decisions

  • Home location (43.2419, -70.9164458) defaults to Dover NH; override with HOME_LAT/HOME_LON
  • TPMS alert dedup tracks per-wheel AND the allLamps flag independently — critical escalation fires even if per-wheel alerts were already sent
  • monitor-fuel.ts left intact for backward compatibility; crontab and entrypoint.sh updated to use monitor.ts

Test plan

  • 57 tests total; 53 pass; 4 pre-existing CanadianVehicle failures (exist on main, unrelated to this PR)
  • New: 26 tests covering SQLite operations, TPMS logic, and temperature fetch
  • ESLint clean
  • TEST_ALERT=tpms npm run monitor for manual TPMS alert verification
  • TEST_ALERT=low npm run monitor for manual fuel alert verification

Closes #4
Closes #5

🤖 Generated with Claude Code

- Add src/vehicle-db.ts — SQLite DB (3 tables: checks, tpms_readings,
  alerts) via better-sqlite3; WAL mode; foreign keys enforced
- Add src/monitor-helpers.ts — pure helpers: fetchOutdoorTempF
  (Open-Meteo, no key), newlyLitWheels, tpmsSeverity
- Add monitor.ts — combined polling script: one vehicle.status() call
  drives both fuel-level checks and TPMS lamp checks; temperature
  logged for correlation; fill-ups trigger vehicle.odometer(); SQLite
  writes every run
- Extend alert-backends.ts — FuelAlertMessage | TpmsAlertMessage union
  type; both Console and ntfy backends handle both kinds
- TPMS dedup tracks per-wheel + allLamps flag independently; allLamps
  re-arms after per-wheel alerts are already sent (critical escalation)
- deployment/crontab and entrypoint.sh updated to use monitor.ts
- Dockerfile: add python3 make g++ for better-sqlite3 native build
- .env.example: HOME_LAT/HOME_LON, FUEL_FILLUP_THRESHOLD, VEHICLE_DB_PATH
- 26 new tests (vehicle-db ×8, monitor-logic ×14, fetch-temp ×4)
- 57 tests total; 53 pass; 4 pre-existing CanadianVehicle failures

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
dispatch-bot[bot] and others added 2 commits April 16, 2026 03:01
…lyLitWheels

TypeScript inferred `result` as `Array<'frontLeft'|'frontRight'|'rearLeft'|'rearRight'>`
from the wheels.filter call, then rejected `result.push('allLamps')` since `'allLamps'`
is not in that union. The function return type is already `string[]`, so an explicit
annotation aligns the inferred type with the intent.

Closes #7

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@tclancy
tclancy merged commit 4e68dc6 into main Apr 16, 2026
2 checks passed
@tclancy
tclancy deleted the claude/tpms-fuel-sqlite-4-5 branch April 16, 2026 14:06
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.

Research: Fuel Usage Research: Tire Pressue

1 participant