integration icon indicating copy to clipboard operation
integration copied to clipboard

Suggestion: skip Restart required when a custom integration can be hot-loaded

Open magicbear opened this issue 3 months ago • 4 comments

Feature / suggestion

After HACS downloads a custom integration (first install or update), Home Assistant does not always need a full Core restart.

A custom integration can be made available in-process by:

  1. Refreshing the loader cache (DATA_CUSTOM_COMPONENTS / async_get_custom_components) so Add integration sees the new domain
  2. On update, if manifest.json requirements (and bundled native libs) did not change: unload existing config entries, drop custom_components.<domain>* from sys.modules, importlib.invalidate_caches(), then set the entries up again

Already-imported third-party packages and C extensions cannot be swapped in a running interpreter. If requirements changed, a restart is still the right answer. Updating HACS itself should also keep requiring a restart.

We implemented this as a small companion integration that hooks HacsIntegrationRepository.async_pre_install / async_post_installation and clears pending_restart when a hot load is safe:

https://github.com/magicbear/hacs_hot_reload

It is mainly a developer tool (iterate on custom_components without waiting for a full restart). Sharing it in case HACS wants to offer something similar natively — for example only skip the Restart required repair when the above path succeeds, instead of always setting pending_restart after a download.

Happy to turn this into a PR against HACS if that would be useful; otherwise this issue can just be a pointer to the approach.

magicbear avatar Aug 30 '26 19:08 magicbear

Thank you for opening an issue in the HACS.

Before proceeding, please verify the following:

Select the correct issue template: HACS provides different templates for different types of bugs. Choosing the right template ensures you're asked the right questions and helps route your bug appropriately.

Complete the ENTIRE issue template: Make sure you've read the issue guidelines and filled out every single field in the issue template, even if some fields seem unrelated to your specific situation.

Fill out everything, even if it seems unnecessary: Don't skip fields because they "don't seem relevant" to your bug. The template asks for specific information because:

  • Problems often have unexpected causes that surface through "unrelated" details
  • What seems unrelated to you might be the key to solving your bug
  • Incomplete information requires follow-up questions, delaying resolution
  • The template is designed based on years of troubleshooting experience
  • Missing information forces those helping to make assumptions, which can lead to wrong solutions

Issues with incomplete templates take significantly longer to resolve or may be closed without resolution.

If you're experiencing a similar bug: If your bug is identical to an existing one, please:

  • Add a 👍 reaction to the original issue description
  • Subscribe to notifications on that issue to stay updated
  • Do not add comments like "same here", "I have this too", or "+1"

Adding duplicate comments creates noise and makes it harder to track and resolve issues. Reactions help prioritize issues based on how many users are affected.

Getting help: If you need assistance filling out the template or understanding your issue:

What happens next: Maintainers and community members will review your issue and may:

  • Ask for additional information if the template is incomplete
  • Provide a solution or workaround
  • Label the issue appropriately for tracking
  • Link it to related issues or pull requests

hacs-bot avatar Aug 30 '26 19:08 hacs-bot

The bot reply above is the standard bug-template checklist. This issue is not a bug report.

It is a feature suggestion (and a pointer to a working companion): after HACS downloads a custom integration, Home Assistant can often hot-load it without a full Core restart, so HACS does not always need to set pending_restart / show Restart required.

There is no feature-request template here, so this was opened as a plain issue on purpose. Please do not expect System Health, debug logs, or a diagnostics dump — those do not apply.

Companion implementation (developer tool): https://github.com/magicbear/hacs_hot_reload

If GitHub issues are only for bugs, feel free to close this; Discord is fine too.

magicbear avatar Aug 30 '26 19:08 magicbear

This would be extremely valuable for custom integration development.

One important distinction is that Home Assistant already supports reloading many config entries, but that is not the same as reloading the integration code itself.

For developers, the expensive part is usually changing Python code, being forced to restart Core, waiting for startup, and then repeating the process again and again.

I especially like the proposed approach of:

  • unloading config entries,
  • removing custom_components.<domain>* from sys.modules,
  • invalidating Python import caches,
  • and only attempting a hot reload when requirements have not changed.

A best-effort, developer-oriented hot reload would already provide significant value, even if some situations still require a full restart.

As an additional reference, other home automation platforms already provide similar developer-focused functionality. IP-Symcon, for example, offers MC_ReloadModule, which allows developers to reload a module/library during development without restarting the entire system.

Home Assistant's architecture is obviously different, so the implementation details would not be the same. However, it demonstrates that reducing restart cycles can have a significant positive impact on development velocity and developer experience.

In my opinion, this could eventually evolve into a Home Assistant Core capability, with HACS acting as an early adopter and proving ground for the concept.

Thanks for exploring this idea and for providing a proof-of-concept implementation.

7weazel7 avatar Oct 09 '26 11:10 7weazel7

Thanks for the suggestion.

HACS is moving into Home Assistant as the Marketplace integration (see #5590), so new features won't land here anymore. Please open a discussion in the Marketplace category, or join one if it already exists, so it gets picked up there.

Marketplace already skips the restart after a first install of a config flow integration. Updates still need a restart.

Closing this one.

../Frenck

                       

Blogging my personal ramblings at frenck.dev

frenck avatar Oct 16 '26 19:10 frenck