Repository navigation
Poll only while watching for the bus (v0.5.1) - #2
Conversation
The provider is polled only while a profile is in its watch window and the bus hasn't reached the stop yet today. Outside that, Bus Monitor keeps the last known positions and makes no requests; "where is the bus?" fetches once on demand so the answer is still current. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 85427eb779
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if self.data is not None and not self.needs_positions(now): | ||
| # Nothing to watch: keep the last positions and spare the provider a request. | ||
| data = self.data | ||
| else: | ||
| data = await self._fetch_positions() |
There was a problem hiding this comment.
Discard stale heading history when polling resumes
When polling resumes the next morning, TripTracker.prev still contains yesterday's arrival position. Although _crossed() rejects segments older than MAX_SEGMENT_GAP, _heading() does not: it derives a heading from yesterday's stop to today's position, overriding the current GPS course. For a bus approaching a checkpoint south of the stop, this produces a southbound heading and suppresses the checkpoint alert even though the bus is traveling north toward the stop. I reproduced the missing alert with paused polling; feeding an intervening position, as continuous polling previously did, produces the alert. Clear or age-limit the previous position used for heading inference when resuming after a pause.
Useful? React with 👍 / 👎.
What
Bus Monitor now calls the tracking provider (Bouncie or Traccar) only while a profile is watching: inside its watch window (days and times) and only until the bus reaches the stop that day.
describe_location) fetches once on demand when polling is paused, so the spoken answer is current.Why
Before this, Bus Monitor polled all day, every day. With the Bouncie default of every 30 s, that's about 2,880 requests a day per account, almost all of them outside the times anyone cares about. A typical 1–2 hour window that stops at arrival cuts that by roughly 90%.
Reviewer notes
_crossedalready ignores segments longer thanMAX_SEGMENT_GAP(120 s). So that first fix is only checked against where the bus actually is.tick()still runs on every coordinator interval. It needs no provider call, and it already did nothing outside the window or after arrival.Tests
ruff,pytest(97 tests) and hassfest (run locally in Docker) all pass. The newtests/test_polling.pycovers:wants_positionacross the window, weekends, arrival and the next daydescribe_locationfetching on demand.The three HA-level tests fail without the change.
🤖 Generated with Claude Code