432 Commits

Author SHA1 Message Date
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 6de2defa0586165c2918ce006cf57aa3acaae730.

* 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 e8f12aad5579a1e5e3930957a46ea6f3dd9beecf.

* 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
J. Nick Koston
08897137ff
Pre-import more frontend deps to avoid importing when the event loop is running (#112031) 2024-03-02 13:44:06 -10:00
Paulus Schoutsen
9512fb420d
Import cryptography OpenSSL backend (#111840)
* Import cryptography OpenSSL backend

* No need to impor top-level. Included.

* Update homeassistant/bootstrap.py
2024-02-29 10:28:32 -05:00
J. Nick Koston
9f8fbb747e
Pre-import api, config, and lovelace in bootstrap to avoid loading them at runtime (#111752) 2024-02-28 15:40:16 -10:00
J. Nick Koston
5bf7a00989
Move DATA_LOGGING constant to homeassistant.const (#111763) 2024-02-28 14:09:51 -10:00
J. Nick Koston
61f6df527e
Import cryptography early since importing openssl is not thread-safe (#111768) 2024-02-28 19:00:17 -05:00
J. Nick Koston
459f430575
Use eager tasks in a few more places in bootstrap (#111697)
I missed a few of the ones that run before we call
_async_set_up_integrations as I was too focused
on the timings of that function
2024-02-28 12:41:03 +01:00
Joakim Sørensen
f622ddef47
Move backup/* WS commands to the backup integration (#111636)
Revert "Revert "Move backup/* WS commands to the backup integration" (#111136)"

This reverts commit 8f834268955966d93bbc85b2ae7e86e6da46e37f.
2024-02-27 11:56:07 -05:00
J. Nick Koston
f08122084b
Reduce bootstrap code (#111450)
* Reduce bootstrap code

Adds a SETUP_ORDER const dict which will be used
for future refactoring

* tweak

* fix bad merge
2024-02-26 23:58:16 -05:00
J. Nick Koston
de48ad5931
Create bootstrap tasks eagerly (#111497)
We can avoid one event loop iteration to start the tasks here
2024-02-26 23:56:16 -05:00
J. Nick Koston
145ce183d0
Create component setup tasks eagerly in bootstrap (#111511)
This saves waiting one iteration of the event loop
2024-02-26 23:45:55 -05:00
Joakim Sørensen
8f83426895
Revert "Move backup/* WS commands to the backup integration" (#111136)
Revert "Move backup/* WS commands to the backup integration (#110651)"

This reverts commit ec4e6c3a7435400cf1a9afdf2c84165be957f294.
2024-02-22 16:08:30 +01:00
Joakim Sørensen
ec4e6c3a74
Move backup/* WS commands to the backup integration (#110651)
* Move backup/* WS commands to the backup integration

* Call correct command

* Use debug for logging

* Remove assertion of hass.data for setup test

* parametrize token fixture
2024-02-22 10:25:38 +01:00
Franck Nijhof
e0a9dcd996
Add label registry (#110821) 2024-02-19 11:59:08 +01:00
J. Nick Koston
3633700d97
Fix sending multiple empty integration timing in bootstrap (#110872) 2024-02-18 19:53:05 +01:00
J. Nick Koston
16653ff5d0
Group loading of translations for integrations to reduce executor jobs at startup (#110674) 2024-02-17 21:08:55 -06:00
J. Nick Koston
def6c5c21c
Refactor integration startup time tracking to reduce overhead (#110136)
* Refactor integration startup time tracking to reduce overhead

- Use monotonic time for watching integration startup time as it avoids incorrect values if time moves backwards because of ntp during startup and reduces many time conversions since we want durations in seconds and not local time

- Use loop scheduling instead of a task

- Moves all the dispatcher logic into the new _WatchPendingSetups

* websocket as well

* tweaks

* simplify logic

* preserve logic

* preserve logic

* lint

* adjust
2024-02-17 21:47:55 -05:00
Franck Nijhof
4570eed6f6
Add floor registry (#110741)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-02-17 21:21:15 +01:00
J. Nick Koston
1260c5a909
Speed up bootstrap by preloading manifests for base platforms (#110130) 2024-02-16 09:35:46 -06:00
Piotr Machowski
a2f4e99994
Add state_translated function to jinja templates (#96906)
* Add state_translated jinja function

* Add tests for load_state_translations_to_cache and get_cached_translations

* Cleanup state_translated template

* Add tests for state_translated jinja function

* Apply black formatting

* Improve code quality

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Prevent invalid components from loading translations

* Refactor loading translations to cache

* Adjust code issues

* Update homeassistant/helpers/translation.py

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Refactor listeners that trigger translation loading

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Adjust invalid function calls, fix code styling

* Adjust code quality

* Extract async_translate_state function

* Apply suggestions from code review

Co-authored-by: Erik Montnemery <erik@montnemery.com>

* Apply suggestions from code review

* Fix tests

* Fix tests

---------

Co-authored-by: Piotr Machowski <PiotrMachowski@users.noreply.github.com>
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-02-10 10:47:56 +01:00
Marc Mueller
cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
Franck Nijhof
80207835d7
Move core fundamental components into bootstrap (#105560)
Co-authored-by: Erik <erik@montnemery.com>
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-01-22 20:09:48 +01:00
J. Nick Koston
69307374f4
Signficantly reduce executor contention during bootstrap (#107312)
* Signficantly reduce executor contention during bootstrap

At startup we have a thundering herd wanting to use the executor
to load manifiest.json. Since we know which integrations we are
about to load in each resolver step, group the manifest loads
into single executor jobs by calling async_get_integrations on
the deps of the integrations after they are resolved.

In practice this reduced the number of executor jobs
by 80% during bootstrap

* merge

* naming

* tweak

* tweak

* not enough contention to be worth it there

* refactor to avoid waiting

* refactor to avoid waiting

* tweaks

* tweaks

* tweak

* background is fine

* comment
2024-01-07 22:55:40 -05:00
Erik Montnemery
3bcc6194ef
Add domain key config validation (#104242)
* Drop use of regex in helpers.extract_domain_configs

* Update test

* Revert test update

* Add domain_from_config_key helper

* Add validator

* Address review comment

* Update snapshots

* Inline domain_from_config_key in validator
2023-12-05 15:07:32 +01:00
Jan Bouwhuis
9962301b42
Do not notify config errors during logging (#104466) 2023-11-24 21:34:09 +01:00
Erik Montnemery
654c4b6e35
Use core domain constant in bootstrap (#104061) 2023-11-16 11:26:57 +01:00
Erik Montnemery
5b37096b5f
Refactor config.async_log_exception (#104034)
* Refactor config.async_log_exception

* Improve test coverage

* Make functions public
2023-11-15 19:09:49 +01:00
Marc Mueller
a70ec64408
Update mypy to 1.7.0 (#103800) 2023-11-11 23:31:04 +01:00
Erik Montnemery
97cc05d0b4
Make it possible to restart core in safe mode (#102606) 2023-10-24 14:47:58 +02:00
Erik Montnemery
b953f2998c
Rename the safe_mode integration to recovery_mode (#102581)
* Rename safe mode integration to recovery mode

* Update code
2023-10-24 09:11:14 +02:00
Erik Montnemery
c481fdb7d0
Rename safe mode to recovery mode (#102580) 2023-10-23 20:33:08 +02:00
Erik Montnemery
91faa53843
Don't allow hass.config.config_dir to be None (#98442) 2023-08-16 13:00:14 +02:00
Erik Montnemery
3b9d6f2dde
Add setup function to the component loader (#98148)
* Add setup function to the component loader

* Update test

* Setup the loader in safe mode and in check_config script
2023-08-15 10:59:42 +02:00
Jan-Philipp Benecke
99ee4e8a42
Set httpx log level to warning (#94217)
Set log level of httpx to warning
2023-06-08 09:39:06 +02:00
J. Nick Koston
fba826ae9e
Migrate restore_state helper to use registry loading pattern (#93773)
* Migrate restore_state helper to use registry loading pattern

As more entities have started using restore_state over time, it
has become a startup bottleneck as each entity being added is
creating a task to load restore state data that is already loaded
since it is a singleton

We now use the same pattern as the registry helpers

* fix refactoring error -- guess I am tired

* fixes

* fix tests

* fix more

* fix more

* fix zha tests

* fix zha tests

* comments

* fix error

* add missing coverage

* s/DATA_RESTORE_STATE_TASK/DATA_RESTORE_STATE/g
2023-05-30 20:48:17 -05:00