Skip to content

Implement debounced writes for HACS data stores#5293

Draft
ludeeus wants to merge 4 commits into
mainfrom
claude/loving-thompson-LojR0
Draft

Implement debounced writes for HACS data stores#5293
ludeeus wants to merge 4 commits into
mainfrom
claude/loving-thompson-LojR0

Conversation

@ludeeus

@ludeeus ludeeus commented May 30, 2026

Copy link
Copy Markdown
Member

No description provided.

claude added 2 commits May 30, 2026 10:43
The HA Update entity flow (`update.async_install` →
`repository.async_download_repository` → `_async_post_install`) never
called `async_write`, so updates only landed on disk when the next
unrelated websocket action fired or when
`EVENT_HOMEASSISTANT_FINAL_WRITE` ran at shutdown. On Docker installs
the container is often killed without a graceful stop and the event
never fires, so HACS forgets it had updated the repository.

Schedule a debounced write at the end of `_async_post_install` via
`Store.async_delay_save` so every install path persists, while bursts
(bulk updates, queued installs) coalesce into a single disk write per
store. HA's Store also flushes pending delayed saves on shutdown for
free, so the existing `EVENT_HOMEASSISTANT_FINAL_WRITE` safety net
stays as belt-and-braces.

Refactor `HacsData` to use pure sync builders for the three store
payloads (`hacs`, `data`, `repositories`) so both the eager
`async_write` path and the new `async_schedule_write` path share the
same assembly logic without relying on a mutable `self.content`
side-effect.
Copilot AI review requested due to automatic review settings May 30, 2026 10:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors HACS data persistence to support debounced writes via a new async_delay_save_to_store() helper and a HacsData.async_schedule_write() method, with data-building logic extracted into pure _build_* callbacks. Repository post-install now triggers a scheduled write instead of relying on the caller to flush immediately.

Changes:

  • Add async_delay_save_to_store() wrapper around Store.async_delay_save in utils/store.py.
  • Split HacsData write path into pure _build_hacs_data/_build_repositories_data/_build_experimental_data and rename per-repo helpers to _repository_export/_experimental_repository_export; add async_schedule_write().
  • Call self.hacs.data.async_schedule_write() at the end of _async_post_install.

Reviewed changes

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

File Description
custom_components/hacs/utils/store.py New async_delay_save_to_store helper that delegates to Store.async_delay_save on a store fetched via get_store_for_key.
custom_components/hacs/utils/data.py Refactors data export to pure builders and introduces async_schedule_write using the new delayed-save helper.
custom_components/hacs/repositories/base.py Schedules a debounced data write after post-install steps complete.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread custom_components/hacs/utils/store.py
Comment thread custom_components/hacs/utils/data.py
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