Skip to content

Fix remote calendar state after refresh#170972

Open
Sean-Kenneth-Doherty wants to merge 2 commits into
home-assistant:devfrom
Sean-Kenneth-Doherty:codex/remote-calendar-refresh-state
Open

Fix remote calendar state after refresh#170972
Sean-Kenneth-Doherty wants to merge 2 commits into
home-assistant:devfrom
Sean-Kenneth-Doherty:codex/remote-calendar-refresh-state

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 17, 2026

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

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New integration (thank you!)
  • New feature (which adds functionality to an existing integration)
  • Deprecation (breaking change to happen in the future)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Additional information

Checklist

  • I understand the code I am submitting and can explain how it works.
  • The code change is tested and works locally.
  • Local tests pass. Your PR cannot be merged unless tests pass
  • There is no commented out code in this PR.
  • I have followed the development checklist
  • I have followed the perfect PR recommendations
  • The code has been formatted using Ruff (ruff format homeassistant tests)
  • Tests have been added to verify that the new code works.
  • Any generated code has been carefully reviewed for correctness and compliance with project standards.

If user exposed functionality or configuration variables are added/changed:

If the code communicates with devices, web services, or third-party tools:

  • The manifest file has all fields filled out correctly.
    Updated and included derived files by running: python3 -m script.hassfest.
  • New or updated dependencies have been added to requirements_all.txt.
    Updated by running python3 -m script.gen_requirements_all.
  • For the updated dependencies a diff between library versions and ideally a link to the changelog/release notes is added to the PR description.

To help with the load of incoming pull requests:

Copilot AI review requested due to automatic review settings May 17, 2026 11:46
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sean-Kenneth-Doherty

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!

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@home-assistant home-assistant Bot marked this pull request as draft May 17, 2026 11:46
@home-assistant
Copy link
Copy Markdown
Contributor

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks 👍

Learn more about our pull request process.

@home-assistant
Copy link
Copy Markdown
Contributor

Hey there @Thomas55555, @allenporter, mind taking a look at this pull request as it has been labeled with an integration (remote_calendar) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of remote_calendar can trigger bot actions by commenting:

  • @home-assistant close Closes the pull request.
  • @home-assistant mark-draft Mark the pull request as draft.
  • @home-assistant ready-for-review Remove the draft status from the pull request.
  • @home-assistant rename Awesome new title Renames the pull request.
  • @home-assistant reopen Reopen the pull request.
  • @home-assistant unassign remote_calendar Removes the current integration label and assignees on the pull request, add the integration domain after the command.
  • @home-assistant update-branch Update the pull request branch with the base branch.
  • @home-assistant add-label needs-more-information Add a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) to the pull request.
  • @home-assistant remove-label needs-more-information Remove a label (needs-more-information, problem in dependency, problem in custom component, problem in config, problem in device, feature-request) on the pull request.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +104 to +124
@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()
Copy link
Copy Markdown
Contributor

@home-assistant home-assistant Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Sean-Kenneth-Doherty

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!

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 17, 2026 13:24
Copilot AI review requested due to automatic review settings May 17, 2026 13:24
@home-assistant home-assistant Bot dismissed stale reviews from themself May 17, 2026 13:24

Stale

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

END:VCALENDAR
"""
)
respx.get(CALENDER_URL).mock(
Comment on lines +105 to +124
@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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants