Recompute the local calendar event instead of caching it - #178763
Draft
soldier2008 wants to merge 1 commit into
Draft
Recompute the local calendar event instead of caching it#178763soldier2008 wants to merge 1 commit into
soldier2008 wants to merge 1 commit into
Conversation
The entity cached the upcoming event and only refreshed it in async_update, so the alarm scheduled for the end of the current event wrote the state while still holding the finished one. With two adjacent events that turned the calendar off until the next platform poll picked the new one up. Materializing a bounded timeline on update and scanning it on access is what remote_calendar already does since home-assistant#163186.
Contributor
|
Hey there @allenporter, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes local calendar state gaps between adjacent events by recomputing the active event from a bounded timeline.
Changes:
- Materializes upcoming events during updates.
- Adds regression coverage for adjacent events.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
homeassistant/components/local_calendar/calendar.py |
Recomputes events from a materialized timeline. |
tests/components/local_calendar/test_calendar.py |
Tests uninterrupted state across adjacent events. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
|
|
||
| @pytest.mark.parametrize("ics_content", [ADJACENT_EVENTS_ICS]) | ||
| async def test_adjacent_events_stay_on( |
| self._calendar.timeline_tz(now.tzinfo), | ||
| start=now, | ||
| stop=now + MAX_LOOKAHEAD_TIME, | ||
| max_number_of_events=MAX_LOOKAHEAD_EVENTS, |
soldier2008
marked this pull request as draft
August 11, 2026 17:10
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed change
The entity cached the upcoming event in
self._eventand only refreshed it inasync_update. The alarm thatCalendarEntityschedules for the end of the current event writes the state without going throughasync_update, so it wrote the state whileself._eventstill held the event that had just finished. With two adjacent events the calendar therefore turned off at the boundary and only came back on the next platform poll.Materializing a bounded timeline on update and scanning it on access removes the cache, the same shape
remote_calendarmoved to in #163186.Kept as a draft: with more events inside one poll interval than
MAX_LOOKAHEAD_EVENTS, the materialized timeline runs out and the state goes off again until the next refresh. Reproduced with 25 adjacent one second events.remote_calendarhas the same bound, so this needs a decision on the pattern rather than a change here alone.Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: