Fix remote calendar state after refresh#170972
Conversation
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍 |
|
Hey there @Thomas55555, @allenporter, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR ensures the remote calendar entity’s “upcoming event” state stays in sync when the DataUpdateCoordinator refreshes by rebuilding the materialized timeline on coordinator updates.
Changes:
- Reworks coordinator update handling to rebuild the materialized timeline and then write entity state.
- Adds a regression test verifying a coordinator refresh updates the entity’s upcoming event attributes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/components/remote_calendar/test_calendar.py | Adds a test that asserts the upcoming event state updates after a coordinator refresh. |
| homeassistant/components/remote_calendar/calendar.py | Updates coordinator update handling to rebuild the materialized timeline and write state. |
| @callback | ||
| def _handle_coordinator_update(self) -> None: | ||
| """Handle updated data from the coordinator.""" | ||
| if not self.coordinator.last_update_success: | ||
| self.async_write_ha_state() | ||
| return | ||
|
|
||
| self.coordinator.config_entry.async_create_task( | ||
| self.hass, self._async_handle_coordinator_update() | ||
| ) | ||
|
|
||
| async def _async_handle_coordinator_update(self) -> None: | ||
| """Refresh the timeline and write state.""" | ||
| await self._async_update_timeline() | ||
| self.async_write_ha_state() | ||
|
|
||
| async def async_update(self) -> None: | ||
| """Refresh the coordinator and materialized timeline.""" | ||
| await super().async_update() | ||
| if self.coordinator.last_update_success: | ||
| await self._async_update_timeline() |
| } | ||
|
|
||
|
|
||
| @pytest.mark.freeze_time(datetime(2026, 5, 18, 6)) |
| return | ||
|
|
||
| self.coordinator.config_entry.async_create_task( | ||
| self.hass, self._async_handle_coordinator_update() |
There was a problem hiding this comment.
It seems you haven't yet signed a CLA. Please do so here.
Once you do that we will be able to review and accept this pull request.
Thanks!
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
| END:VCALENDAR | ||
| """ | ||
| ) | ||
| respx.get(CALENDER_URL).mock( |
| @callback | ||
| def _handle_coordinator_update(self) -> None: | ||
| """Handle updated data from the coordinator.""" | ||
| if not self.coordinator.last_update_success: | ||
| self.async_write_ha_state() | ||
| return | ||
|
|
||
| if self._manual_update_in_progress: | ||
| return | ||
|
|
||
| self.coordinator.config_entry.async_create_task( | ||
| self.hass, | ||
| self._async_handle_coordinator_update(), | ||
| name="remote calendar timeline update", | ||
| ) | ||
|
|
||
| async def _async_handle_coordinator_update(self) -> None: | ||
| """Refresh the timeline and write state.""" | ||
| await self._async_update_timeline() | ||
| self.async_write_ha_state() |
Breaking change
None.
Proposed change
Remote Calendar stores a materialized upcoming-events timeline for its entity state. When the coordinator refreshed, the entity listener only wrote Home Assistant state, so the state attributes could continue to show the old upcoming event even though the coordinator had newer calendar data.
This refreshes the materialized timeline before writing state on successful coordinator updates, while preserving the unavailable-state write path for failed coordinator updates. It also adds a regression test that updates the mocked ICS response and verifies the entity state moves from the old start time to the refreshed start time.
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: