Commit Graph

416 Commits (63d294e58ed30b1741862379e9e954dc88c65c5e)

Author SHA1 Message Date
Craig Andrews 9e8df72c0d
Improve is docker env checks (#132404)
Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: Sander Hoentjen <sander@hoentjen.eu>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Robert Resch <robert@resch.dev>
2025-01-02 17:21:49 +01:00
J. Nick Koston de1b6a0dfc
Add backup to the list of storage preloads (#133855) 2024-12-22 23:17:13 -05:00
Robert Resch cd12720085
Add Python version to issue ID (#130611) 2024-11-14 16:31:33 +01:00
Erik Montnemery 3e62c6ae2f
Move core config functionality to its own module (#129065)
* Move core config functionality to its own module

* Adjust test
2024-10-24 13:34:51 +02:00
Artur Pragacz 67e3139dcf
Clean up useless logging handler setting (#120974)
Setting level of the handler does effectively nothing,
because HomeAssistantQueueHandler ignores this setting.
Also make the convention of getting the root logger uniform.
2024-08-05 11:22:13 +02:00
Erik Montnemery 3df6b34a03
Split recorder and frontend bootstrap steps (#122420) 2024-07-22 23:07:49 +02:00
Erik Montnemery c73e7ae178
Handle integration with missing dependencies (#122386) 2024-07-22 15:41:55 +02:00
J. Nick Koston adee8094e7
Cache is_official_image/is_docker_env in bootstrap to fix blocking I/O (#121261)
* Cache is_official_image and is_docker_env in bootstrap to fix blocking I/O

These do blocking I/O later in the startup process

discovered in https://github.com/home-assistant/core/pull/120273

* comment
2024-07-05 08:30:07 +02:00
Erik Montnemery b8b7c23258
Create log files in an executor thread (#120912) 2024-07-02 15:48:35 +02:00
Erik Montnemery 7d14b9c5c8
Always create a new HomeAssistant object when falling back to recovery mode (#119969) 2024-06-19 22:45:59 +02:00
J. Nick Koston 6ba8b7a5d6
Remove isal from after_dependencies in http (#119000) 2024-06-07 09:21:53 +02:00
Erik Montnemery f896c7505b
Improve async_get_issue_tracker for custom integrations (#118016) 2024-05-24 09:55:05 +02:00
J. Nick Koston e12d23bd48
Speed up async_get_loaded_integrations (#117851)
* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* Speed up async_get_loaded_integrations

Use a setcomp and difference to find the components to split
to avoid the loop. A setcomp is inlined in python3.12 so its
much faster

* simplify

* fix compat

* bootstrap

* fix tests
2024-05-21 09:08:49 -04:00
J. Nick Koston 437fe3fa4e
Fix mimetypes doing blocking I/O in the event loop (#117292)
The first time aiohttp calls mimetypes, it will load the mime.types file

We now init the db in the executor to avoid blocking the event loop
2024-05-12 10:47:52 +02:00
J. Nick Koston b061e7d1aa
Small speed up to setting up integrations and config entries (#117278)
* Small speed up to setting up integration and config entries

When profiling tests, I noticed many calls to get_running_loop. In the places
where we are already in a coro, pass the existing loop so it does not have to
be looked up. I did not do this for places were we are not in a coro since there
is risk that an integration could be doing a non-thread-safe call and its better
that the code raises when trying to fetch the running loop vs the performance
improvement for these cases.

* fix merge

* missed some
2024-05-11 22:39:20 -04:00
Marc Mueller c50a340cbc
Use HassKey for setup and bootstrap (#116998) 2024-05-07 11:18:20 -05:00
Sid b456d97e65
Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
J. Nick Koston 91fa8b50cc
Turn on thread safety checks in async_dispatcher_send (#116867)
* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* adjust
2024-05-05 16:29:43 -04:00
J. Nick Koston 164403de20
Add thread safety checks to async_create_task (#116339)
* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* Add thread safety checks to async_create_task

Calling async_create_task from a thread almost always results in an
fast crash. Since most internals are using async_create_background_task
or other task APIs, and this is the one integrations seem to get wrong
the most, add a thread safety check here

* missed one

* Update homeassistant/core.py

* fix mocks

* one more internal

* more places where internal can be used

* more places where internal can be used

* more places where internal can be used

* internal one more place since this is high volume and was already eager_start
2024-04-28 18:29:00 -04:00
J. Nick Koston ab2ea6100c
Speed up singleton decorator so it can be used more places (#116292) 2024-04-28 12:11:08 -05:00
J. Nick Koston d17e9bfc99
Enable debug mode if asyncio debug is on at startup (#116084) 2024-04-24 12:55:09 +02:00
J. Nick Koston 53a179088f
Add debug mode to catch unsafe thread operations using core helpers (#115390)
* adjust

* adjust

* fixes

* one more

* test

* debug

* move to config

* cover

* Update homeassistant/core.py

* set debug from RuntimeConfig

* reduce

* fix message

* raise

* Update homeassistant/core.py

* Update homeassistant/core.py

* no flood check for raise

* cover
2024-04-24 03:36:05 +02:00
J. Nick Koston bf5cf382dc
Avoid useless stat() syscalls for every logger record (#114987)
* Avoid useless stat() syscalls for every logger record

shouldRollover will always return False since we do
not use maxBytes as we are only using RotatingFileHandler
for the backupCount option. Since every log record will
stat the log file to see if it exists and if its a normal
file, we can override the shouldRollover to reduce the
logging overhead quite a bit

1d3225ae05/Lib/logging/handlers.py (L189)

* assert False is False
2024-04-05 22:00:09 -04:00
J. Nick Koston 0c3ccabfb1
Speed up logger setup (#114610)
* Speed up logger setup

Preload core.logger and avoid saving it
until after startup

* add comment about 180s

* Adjust grammar

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-04-04 08:35:44 +02:00
J. Nick Koston 5038a035bd
Detect blocking module imports in the event loop (#114488) 2024-03-30 19:51:31 -10:00
J. Nick Koston ef5f6829e7
Fix late load of anyio doing blocking I/O in the event loop (#114491)
* Fix late load of anyio doing blocking I/O in the event loop

httpx loads anyio which loads the asyncio backend in the event loop
as soon as httpx makes the first request

* tweak
2024-03-30 14:56:01 -04:00
J. Nick Koston cabc4f797a
Preload storage for integrations we know we are going to setup (#114192) 2024-03-25 15:49:54 -10:00
J. Nick Koston e8cb6a8e29
Optimize loading of translations (#114089) 2024-03-23 22:22:09 -10:00
J. Nick Koston 31fb02a71d
Fix after deps not being considered for integrations before stage 1 (#114045) 2024-03-23 11:21:56 +01:00
J. Nick Koston 952f47ab18
Combine recorder and frontend bootstrap step (#113985) 2024-03-22 13:50:39 -10:00
J. Nick Koston 7758f41c5a
Load system info with base functionality (#113923) 2024-03-21 09:24:39 +01:00
J. Nick Koston c615b52840
Refactor integration startup time to show wall clock time (#113707)
* Refactor setup time tracking to exclude time waiting on other operations

We now exclude the import time and th time waiting on
base platforms to setup from the setup times

* tweak

* tweak

* tweak

* tweak

* adjust

* fixes

* fixes

* preen

* preen

* tweak

* tweak

* adjust

* tweak

* reduce

* do not count integrtion platforms against their parent integration

* handle legacy tts platforms

* stt as well

* one more wait

* use the same pattern in all the legacy

* fix tts and stt legacy

* fix

* fix

* reduce

* preen

* entity comp does not wait for platforms

* scene blocks as well

* fix test

* test fixes

* coverage

* coverage

* coverage

* fix test

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update tests/test_setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Update homeassistant/setup.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* strip

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* strip WAIT_PLATFORM_INTEGRATION

* remove complexity

* Apply suggestions from code review

* no longer works that way

* fixes

* fixes

* fixes

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-18 21:45:34 -04:00
Sid 6113b99ddd
Replace pylint pointless-statement with ruff B018 (#113582)
* Replace pylint pointless-statement with ruff B018

* fix occurrences of B018

* disable pylint expression-not-assigned as well

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-17 10:58:14 +01:00
J. Nick Koston eb90c9a548
Reduce bottlenecks in bootstrap by ordering the setup of integrations (#113570) 2024-03-15 22:38:06 -10:00
J. Nick Koston 702488062b
Move group config flow pre-import to its init (#113564) 2024-03-15 18:44:10 -10:00
J. Nick Koston 51ece8b1ef
Restore group config_flow pre-import (#113558) 2024-03-15 13:09:20 -10:00
Franck Nijhof 0e2775667d
Add category registry (#110897)
* Add category registry

* Add entity registry support

* Update homeassistant/components/config/entity_registry.py

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Use ulid instead

* Add tests for adding same name in different scopes

* Handle keyerror on update

* Lookup tweak

* Omit categories from entity registry snapshots

* Use base registry

* Update snapshots

* Update snapshots

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-15 13:25:16 +01:00
J. Nick Koston c3b5e819c5
Fix group loading too late resulting in incorrect state (#113262) 2024-03-13 19:18:15 -10:00
J. Nick Koston 9ef0a8cb95
Add default_config to the bootstrap pre-imports (#113263)
This does not make default_config a requirement, it only preloads
the python code for the integration so it does not have to be loaded
when the import executor is busy. While its a tiny init file, it always
ends up at the end of the line and delays startup
2024-03-14 00:15:19 -04:00
J. Nick Koston 65358c129a
Replace periodic tasks with background tasks (#112726)
* Phase out periodic tasks

* false by default or some tests will block forever, will need to fix each one manually

* kwarg works

* kwarg works

* kwarg works

* fixes

* fix more tests

* fix more tests

* fix lifx

* opensky

* pvpc_hourly_pricing

* adjust more

* adjust more

* smarttub

* adjust more

* adjust more

* adjust more

* adjust more

* adjust

* no eager executor

* zha

* qnap_qsw

* fix more

* fix fix

* docs

* its a wrapper now

* add more coverage

* coverage

* cover all combos

* more fixes

* more fixes

* more fixes

* remaining issues are legit bugs in tests

* make tplink test more predictable

* more fixes

* feedreader

* grind out some more

* make test race safe

* one more
2024-03-08 21:45:10 -05:00
Marc Mueller 19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston a6b17dbe68
Schedule polling as periodic tasks (#112640)
* Schedule periodic coordinator updates as background tasks.

Currently, the coordinator's periodic refreshes delay startup because they are not scheduled as background tasks. We will wait if the startup takes long enough for the first planned refresh. Another coordinator's scheduled refresh will be fired on busy systems, further delaying the startup. This chain of events results in the startup taking a long time and hitting the safety timeout because too many coordinators are refreshing.

This case can also happen with scheduled entity refreshes, but it's less common. A future PR will address that case.

* periodic_tasks

* periodic_tasks

* periodic_tasks

* merge

* merge

* merge

* merge

* merge

* fix test that call the sync api from async

* one more place

* cannot chain

* async_run_periodic_hass_job

* sun and pattern time changes from automations also block startup

* Revert "sun and pattern time changes from automations also block startup"

This reverts commit 6de2defa05.

* make sure polling is cancelled when config entry is unloaded

* Revert "Revert "sun and pattern time changes from automations also block startup""

This reverts commit e8f12aad55.

* remove DisabledError from homewizard test as it relies on a race

* fix race

* direct coverage
2024-03-07 23:32:26 -05:00
J. Nick Koston 5da629b3e5
Log waiting tasks in bootstrap that are delaying startup (#112637) 2024-03-07 13:18:18 -10:00
J. Nick Koston 869128e951
Pre import the rest of the recorder platforms before asyncio starts (#112289)
* Pre import the rest of the recorder platforms before asyncio starts

I removed these from #112131 since I had trouble with the weather
tests passing due to a race that I could not figure out. The race
seems to have gone away now (at least locally) so hopefully the CI
will pass now

* Avoid importing counter and proximity integrations in logbook

* Avoid importing counter and proximity integrations in logbook
2024-03-06 20:38:52 -05:00
J. Nick Koston 1772e5257c
Move analytics setup to later stage to avoid delaying frontend startup (#112535)
Move analytics setup to stage 1 to avoid delaying frontend startup

analytics was only needed in the frontend startup phase for onboarding.
Its very unlikely the user will be able to complete the onboarding
steps and get to the analytics screen before analytics is done loading
so we can delay loading it until stage 1. To be absolutely sure that
it is ready, the core_config step in onboarding will wait to proceed
if it is some how still being setup
2024-03-06 20:37:41 -05:00
J. Nick Koston e568f867d2
Adjust MAX_LOAD_CONCURRENTLY constant to allow 6 storage loaders (#112468) 2024-03-05 16:31:10 -10:00
J. Nick Koston d34e2c1f12
Pre import webhook before asyncio starts (#112441)
This one ends in stage 1 and other components have to wait
for it to be imported. Its cheap to import but it ends up
at the end of the line which means other end up waiting for
it which is time we could be doing startup work

`2024-03-04 23:13:04.347 INFO (MainThread) [homeassistant.bootstrap] Setting up stage 1: {usb, websocket_api, webhook, zeroconf, bluetooth, ssdp, dhcp, cloud, network, api, http, hassio}`

It currently always has a wait time for the import executor

`2024-03-04 23:13:04.496 DEBUG (MainThread) [homeassistant.loader] Component webhook import took 0.146 seconds (loaded_executor=True)`
2024-03-05 17:23:18 -05:00
J. Nick Koston 73e1f8a7e5
Pre import image_upload to avoid loading it after asyncio has started (#112444)
image_upload will always be setup because its a dep of person
and since person is a dep of onboarding which is a dep of
frontend its already a base requirement for homeassistant.

Pillow is now listed as a requirement for homeassistant
so we can be sure it installed by the time bootstrap is
loaded

image_upload loading is currently a bottleneck to
get the frontend loaded because it has to load in the
import executor when everything is busy early in startup
2024-03-05 17:22:59 -05:00
J. Nick Koston 40c0b4caf0
Import recorder and common recorder platforms before asyncio starts (#112131) 2024-03-03 22:03:30 -10:00
J. Nick Koston 6a243d6705
Preload platform integrations to better group executor usage (#112010) 2024-03-02 23:03:35 -10:00