1
0
mirror of https://github.com/home-assistant/core.git synced 2025-08-12 06:50:00 +00:00
Commit Graph

403 Commits

Author SHA1 Message Date
J. Nick Koston
6cf1c5c1f2 Hold a lock to prevent concurrent setup of config entries () 2024-04-30 18:47:12 -05:00
Marc Mueller
dace9b32de Store runtime data inside ConfigEntry () 2024-04-30 11:29:43 +02:00
J. Nick Koston
164403de20 Add thread safety checks to async_create_task ()
* 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
3f0c0a72db Prevent setup retry from delaying shutdown () 2024-04-28 08:13:51 -05:00
J. Nick Koston
76639252c9 Make discovery flow tasks background tasks () 2024-04-28 08:13:37 -05:00
Jan Bouwhuis
70b358bca1 Always reload after a successful reauth flow ()
* Always reload after a succesfull reauth-flow

* Add test, fix CI failures

* Add kwarg to prevent reloading and tests

* Do not reload entry for bond if it exists

* Remove mocks on internals

* Rename kwarg to always_reload

* Update tests/components/weatherflow_cloud/test_config_flow.py

* Update tests/components/homeworks/test_config_flow.py

* Update tests/components/homeworks/test_config_flow.py

* Rename to option to reload_even_if_entry_is_unchanged
2024-04-24 15:13:33 +02:00
J. Nick Koston
e9e401ae29 Migrate discovery debouncer callback to async_fire_internal () 2024-04-24 11:26:48 +02:00
J. Nick Koston
f62a3a7176 Simplify config_entries entity registry filter () 2024-04-17 09:42:23 -05:00
J. Nick Koston
14b794b0f7 Migrate config entry reauth to use eager_start () 2024-04-13 18:38:33 -05:00
J. Nick Koston
ee535ee611 Ensure test async_create_task eager start behavior matches production () 2024-04-13 15:58:52 -05:00
J. Nick Koston
08e2b655be Migrate EntityRegistryDisabledHandler to use async_schedule_reload ()
async_schedule_reload ensures that any setup retries are cancelled
before executing the reload. Its unlikely in this case but its
still possible
2024-04-13 16:30:59 -04:00
J. Nick Koston
82d0f478a5 Hold the reload lock while attempting config entry setup retry () 2024-04-13 15:26:41 -05:00
J. Nick Koston
28bdbec14e Bypass ConfigEntry __setattr__ in __init__ ()
ConfigEntries.async_initialize was trigger asyncio warnings because of the CPU time
to call __setattr__ for every variable for each ConfigEntry being loaded at startup
2024-04-11 22:16:01 -04:00
J. Nick Koston
ca5ed274cb Deprecate calling async_listen and async_listen_once with run_immediately () 2024-04-08 10:07:54 -10:00
Marc Mueller
4e94f11665 Use EventType for entity_registry_updated () 2024-04-08 08:44:59 -10:00
J. Nick Koston
29bc67234e Make eager_start default to True for config entry async_create_task () 2024-04-06 11:22:02 -10:00
J. Nick Koston
52957849cf Make eager_start default to True for config entry async_create_background_task () 2024-04-06 10:59:24 -10:00
Marc Mueller
81d682874f Update typing extensions to 4.11.0 () 2024-04-06 14:23:32 +02:00
Marc Mueller
816ce116bf Remove unnecessary functools.cached_property backport () 2024-04-04 11:24:26 +02:00
J. Nick Koston
ef047707d9 Simplify config entry cache clear ()
same as  but for config entries
2024-04-03 12:21:37 +02:00
J. Nick Koston
41a88c876d Avoid useless done check in config entries async_create_task ()
If the task is not started with eager_start it will
never be done right away
2024-04-03 11:49:32 +02:00
Sid
6587ee20db Enable Ruff TRY300 ()
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01:00
G Johansson
fc4d960d17 Add translation support to Config Entry errors ()
* Config Entry error translation

* split key and placeholders

* Fix config entries tests

* translation optional

* Mods
2024-03-28 10:52:21 +01:00
Marc Mueller
911a31f860 Use SignalType to improve typing [core] () 2024-03-27 14:25:02 +01:00
Marc Mueller
d0ecad78ac Revert "Update typing-extensions to 4.11.0rc1 ()" () 2024-03-25 20:44:57 -10:00
Joost Lekkerkerker
6bb4e7d62c Bump ruff to 0.3.4 ()
Co-authored-by: Sid <27780930+autinerd@users.noreply.github.com>
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-26 00:02:16 +01:00
Marc Mueller
188dbfbd2a Update typing-extensions to 4.11.0rc1 () 2024-03-25 11:27:47 +01:00
J. Nick Koston
d0dc820ced Cancel config entry setup retry at shutdown () 2024-03-24 09:09:24 -10:00
J. Nick Koston
4f18f0d902 Fix setup timings when config entry platform loads are not awaited ()
* Move setup time logging into the context manager

We were fetching the time twice but since the context
manager already has the timing, move it there

* remove log setup assertions from integration test

* tweak logging to give us better data for tracking issues

* redundant

* adjust

* preen

* fixes

* adjust

* make api change internal so nobody uses it

* coverage

* fix test

* fix more tests

* coverage

* more tests assuming internal calls

* fix more

* adjust

* adjust

* fix axis tests

* fix broadlink -- it does not call async_forward_entry_setup

* missed some

* remove useless patch

* rename, detect it both ways

* clear

* debug

* try to fix

* handle phase finishing out while paused

* where its set does not need to know its late as that is an implemenation detail of setup

* where its set does not need to know its late as that is an implemenation detail of setup

* tweak

* simplify

* reduce complexity

* revert order change as it makes review harder

* revert naming changes as it makes review harder

* improve comment

* improve debug

* late dispatch test

* test the other way as well

* Update setup.py

* Update setup.py

* Update setup.py

* simplify

* reduce
2024-03-23 15:26:38 -04:00
J. Nick Koston
3b66328591 Add a fast path for async_get_platform () 2024-03-21 09:34:33 +01:00
Erik Montnemery
d31124d5d4 Avoid creating unneeded Context and Event objects when firing events ()
* Avoid creating unneeded Context and Event objects when firing events

* Add test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-20 09:40:06 +01:00
J. Nick Koston
c615b52840 Refactor integration startup time to show wall clock time ()
* 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
J. Nick Koston
6a6f3d46a9 Create config entry async_on_unload tasks eagerly () 2024-03-16 14:43:49 -10:00
J. Nick Koston
6e3e2d1693 Shutdown config entry manager immediately at the stop event () 2024-03-16 13:39:31 -10:00
G Johansson
e8de1a7031 Revert "Avoid pre-importing config_flows if the integration does not … ()
Revert "Avoid pre-importing config_flows if the integration does not support …"

This reverts commit 9940f51b95.
2024-03-15 23:15:36 +01:00
J. Nick Koston
9940f51b95 Avoid pre-importing config_flows if the integration does not support migration ()
* Avoid pre-importing config_flows if the integration does support migration

Currently we pre-import the config flow module if it exists since
setting up the config entry required comparing the versions found
in the config_flow.py. We can avoid the pre-import if the integration
does not support async_migrate_entry which means we avoid loading
many config flows in memory at startup.

* cover

* fix missing block

* do not call directly

* its too fast now, the test gets more along

* Update homeassistant/loader.py
2024-03-14 00:13:40 -04:00
J. Nick Koston
e347096ef5 Add a task name to the config entry retry tasks () 2024-03-12 14:19:22 -10:00
J. Nick Koston
65358c129a Replace periodic tasks with background tasks ()
* 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] () 2024-03-08 10:36:11 -05:00
J. Nick Koston
a6b17dbe68 Schedule polling as periodic tasks ()
* 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
Erik Montnemery
82efb3d35b Make FlowResult a generic type () 2024-03-07 12:41:14 +01:00
Erik Montnemery
3d3e9900c3 Add TypeVar default for FlowResult ()
Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com>
2024-03-05 22:52:11 +01:00
J. Nick Koston
a277d0c4b5 Migrate system flows to use the discovery helper ()
Ensures we are not creating new flows or loading
their platforms until the started event
once the import executor has clamed down
2024-03-05 10:01:31 -05:00
J. Nick Koston
7cb8a8bbc9 Migrate remaining calls in config modules to async_get_component ()
* Migrate remaining calls in config modules to async_get_component

There were a few cases that were still using get_component that
could have done blocking I/O in the event loop, although it
was unlikely.

The caching check in async_get_component has been moved
up to avoid creating the future if the module is already in
the cache

* fix one more
2024-03-05 09:59:52 -05:00
J. Nick Koston
2c179dc5fb Reduce some linear searches to cleanup the device registry ()
Some of the data we had to search for was already available
in a dict or underlying data structure. Make it available
instead of having to build it every time.

There are more places these can be used, but I only did
the device registry cleanup for now
2024-03-04 20:59:12 -05:00
J. Nick Koston
5227976aa2 Group loading of platforms in the import executor ()
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-03 21:32:19 -10:00
Erik Montnemery
3a5e0c14bf Remove config flow specifics from FlowResult ()
* Remove config flow specifics from FlowResult

* Improve docstring

* Update pylint rules
2024-03-01 13:07:13 +01:00
G Johansson
9989a63cdf Add reconfigure step to config flow ()
* Initial commit reconfigure

* test config config_entries

* Fix reconfigure

* test_config_entries

* review comment

* No reconfigure if reauth ongoing

* Fix tests

* Fix tests

* handle source creating flows

* combine

* No black

* Also check reconfigure in reauth flow

* Fix support

* Add entry id

* reset data entry flow

* Mods

* context data

* reset formatting

* Fix config flow platforms

* Fix tests

* Fix step message

* Handling reconfigure step

* Fix more tests

* Config entries tests

* entry_id always means reconfigure

* Mods

* Remove no longer valid exception

* Fixes

* reset silabs test

* dev reg

* resets

* assist pipeline

* Adjust config_entries

* Fix

* Fixes

* docstrings

* Review comment

* docstring
2024-03-01 12:29:35 +01:00
Erik Montnemery
a0e558c457 Add generic classes BaseFlowHandler and BaseFlowManager ()
* Add generic classes BaseFlowHandler and BaseFlowManager

* Migrate zwave_js

* Update tests

* Update tests

* Address review comments
2024-02-29 16:52:39 +01:00
J. Nick Koston
63c3d6e113 Fix race in config entry setup again ()
Because the setup again was scheduled as a task, it would
not unset self._async_cancel_retry_setup in time and we would
try to unsub self._async_cancel_retry_setup after it had already
fired. Change it to call a callback that runs right away so it
unsets self._async_cancel_retry_setup as soon as its called
so there is no race

fixes 
2024-02-29 15:47:36 +01:00