Commit graph

112 commits

Author SHA1 Message Date
epenet 7af79ba013
Add MockModule type hints in tests (#120007) 2024-06-21 11:11:48 +02:00
epenet 01be5d5f6b
Move fixtures to decorators in core tests (#119675) 2024-06-14 13:32:42 +02:00
epenet 9f41133bbc
Add missing argument type to core tests (#119667) 2024-06-14 08:42:01 +02:00
epenet 65befcf5d4
Fix import pylint warning in core tests (#119359) 2024-06-11 15:04:00 +02:00
epenet 1c8a9cc3b8
Remove unused caplog fixtures in tests (#119056) 2024-06-07 11:38:56 +02:00
J. Nick Koston 8f94205014
Include a traceback for non-strict event loop blocking detection (#118620) 2024-06-02 06:36:25 -04:00
Erik Montnemery f896c7505b
Improve async_get_issue_tracker for custom integrations (#118016) 2024-05-24 09:55:05 +02:00
J. Nick Koston c5cc9801a6
Cache serialize of manifest for loaded integrations (#117965)
* Cache serialize of manifest for loaded integrations

The manifest/list and manifest/get websocket apis
are called frequently when moving around in the UI.
Since the manifest does not change we can make
the the serialized version a cached property

* reduce

* reduce
2024-05-23 10:52:05 -04:00
J. Nick Koston fb5fc136e8
Avoid falling back to event loop import on ModuleNotFound (#115404) 2024-04-11 16:32:47 -10:00
J. Nick Koston b12c69accb
Fix memory leak when importing a platform fails (#114602)
* Fix memory leak when importing a platform fails

re-raising ImportError would trigger a memory leak

* fixes, coverage

* Apply suggestions from code review
2024-04-01 21:36:48 -04:00
Sid d5f883fbf0
Unignore Ruff PLR in tests (#114470)
* Unignore Ruff PLR in tests

* Address review comments

* review comments

* fix import

* Update test_api.py

* Update test_api.py

* Update test_api.py
2024-04-01 11:11:59 +02:00
Jan-Philipp Benecke d5da0a053b
Deprecate hass.helpers (#114484)
* Deprecate hass.helpers

* Patch

* Patch _REPORTED_INTEGRATIONS set in test

* Fix test

* Update version
2024-03-31 11:44:11 +02:00
Joost Lekkerkerker 6bb4e7d62c
Bump ruff to 0.3.4 (#112690)
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
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
G Johansson e8de1a7031
Revert "Avoid pre-importing config_flows if the integration does not … (#113553)
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 (#113369)
* 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
Paulus Schoutsen 145657dc21
Only load services.yaml for integrations that have it (#112732)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-03-11 19:05:32 +01:00
J. Nick Koston afa69cca38
Import custom components in the executor by default (#112177)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-10 08:41:33 -10:00
Marc Mueller a6b842f818
Add empty line after module docstring (2) [other] (#112738) 2024-03-08 19:16:38 +01:00
J. Nick Koston 1fb9cfe37e
Speed up the frame helper (#112562) 2024-03-06 20:54:09 -10:00
Erik Montnemery 807c3ca76b
Add custom integration block list (#112481)
* Add custom integration block list

* Fix typo

* Add version condition

* Add block reason, simplify blocked versions, add tests

* Change logic for OK versions

* Add link to custom integration's issue tracker

* Add missing file

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-03-06 13:56:47 +01:00
J. Nick Koston 946572e382
Simplify loader preload logic for config_flows (#112290)
We previously checked Integration.config_flow to see if we should
pre-import the config flow, but this is now always set for some
integration like `homeassistant_green`, `hassio`, etc. Instead
we can add it to the rest of the platforms since we already know
which files exist. This simplifies the logic and ensures the pre-import
still happens if the file is there even if its not listed in the
manifest

`2024-03-04 22:54:31.906 DEBUG (MainThread) [homeassistant.loader] Importing platforms for homeassistant_green executor=[config_flow] loop=[] took 2.74s`
2024-03-05 10:02:23 -05:00
J. Nick Koston 7cb8a8bbc9
Migrate remaining calls in config modules to async_get_component (#112293)
* 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 8b017016b0
Refactor integration platforms to import in the executor (#112168)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 19:21:18 -10:00
J. Nick Koston 1e173e82d0
Add support for preloading platforms in the loader (#112282)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 16:33:12 -10:00
J. Nick Koston 917f0f849d
Import in the executor by default for core integrations (#112127)
* Import in the executor by default for core integration

* merge correct branch in

* Group loading of platforms in the import executor

* adjust test

* remove other pr

* Fix async_prepare_setup_platform test

The message changed because the order changed but was not caught before
merge because it required the combination of PRs to change
the error message

* fix

* tweak

* fix

* self review

* review

* fix hue mocking

* Update homeassistant/loader.py

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>

* lint

* Fix async_get_component loading in the executor when the module is already loaded

The sys.modules check was incorrect (only on dev)

* fix

* Avoid multiple executor jobs with concurrent calls to async_get_component

Return a future that can be awaited if the component is
curently being loaded

* adjust

* coverage

* coverage

* concurrent platforms load test

* doc strings

* coverage

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-04 06:29:32 -05:00
J. Nick Koston 5227976aa2
Group loading of platforms in the import executor (#112141)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-03-03 21:32:19 -10:00
J. Nick Koston 943996b60b
Avoid multiple executor jobs with concurrent calls to async_get_component (#112155) 2024-03-03 20:22:31 -10:00
J. Nick Koston f4b2c9b569
Fix async_get_component loading in the executor when the module is already loaded (#112153) 2024-03-03 17:56:50 -10:00
J. Nick Koston f1eab3f11f
Preload config flow if it exists when loading a component (#112145)
Since config_entries always requires the config_flow to be loaded
to check for migrations, load it if we know it exists when loading
the underlying integration
2024-03-03 21:16:50 -05:00
J. Nick Koston ba9733e90b
Try to preload the config platform when loading a component (#112104) 2024-03-03 10:23:08 -10:00
J. Nick Koston c8cb0ff61d
Avoid trying to import platforms that do not exist (#112028)
* Avoid trying to import platforms that do not exist

* adjust

* fixes

* cleanup

* cleanup

* cleanup

* Apply suggestions from code review

* docs

* fixes

* fixes

* comment

* coverage

* coverage

* coverage

* Switch config to use async_get_component

This was another path where integrations that were marked to load in the executor
would be loaded in the loop

* Switch config to use async_get_component/async_get_platform

This was another path where integrations that were marked to load in the executor
would be loaded in the loop

* merge

* refactor

* refactor

* coverage

* preen

* preen
2024-03-02 22:14:28 -05:00
Marc Mueller 1f173aff17
Fix loader test warning (#111965) 2024-03-01 19:26:44 +01:00
J. Nick Koston ba4120d779
Fallback to event loop import on deadlock (#111868) 2024-02-29 09:01:03 -10:00
Jan-Philipp Benecke bc6b4d01c8
Deprecate hass.components and log warning if used inside custom component (#111508)
* Deprecate @bind_hass and log error if used inside custom component

* Log also when accessing `hass.components`

* Log warning only when `hass.components` is used

* Change version

* Process code review
2024-02-29 12:25:46 +01:00
J. Nick Koston 4ea1c5cc3c
Add support for importing integrations in the executor (#111336)
* Add support for pre-imports at setup time

alternative solution to #111331

* refactor

* refactor

* refactor

* mark >1.0s integrations

* no point in executor if already loaded

* no point in executor if already loaded

* cleanup

* cleanup

* two more

* one more

* analytics loads a lot more integrations

* cloud

* debug

* psutil, hardwre

* try zha

* Update homeassistant/setup.py

* await

* comments

* coverage

* coverage

* coverage

* move logic to loader

* move logic to loader

* preserve comments
2024-02-26 14:49:43 -05:00
J. Nick Koston 3aecec5082
Avoid rechecking for missing platforms in the loader (#111204) 2024-02-23 10:48:47 -10:00
Joakim Plate 523352c97e
Avoid keeping config dir in path (#107760) 2024-01-16 13:38:47 +01:00
Erik Montnemery c481fdb7d0
Rename safe mode to recovery mode (#102580) 2023-10-23 20:33:08 +02:00
Erik Montnemery 17779c5f0c
Add loader.async_suggest_report_issue and loader.async_get_issue_tracker (#101336)
* Add loader.async_suggest_report_issue and loader.async_get_issue_tracker

* Update tests

* Add tests

* Address review comments

* Address review comments
2023-10-04 13:40:33 +02:00
Artur Pragacz e1771ae01e
Fix circular dependancy detection (#100458)
* Fix _async_component_dependencies

Fix bug with circular dependency detection
Fix bug with circular after_dependency detection
Simplify interface and make the code more readable

* Implement review feedback

* Pass all conflicting deps to Exception

* Change inner docstring

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

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-09-28 08:05:00 +02:00
Erik Montnemery 7643820e59
Add loader.async_get_loaded_integration (#99440)
* Add loader.async_get_loaded_integration

* Decorate async_get_loaded_integration with @callback
2023-09-04 14:12:33 +02:00
J. Nick Koston 48485fc2bf
Complete persistent notifications migration (#92828)
* Complete migration of persistent notifications

Persistent notifications are no longer stored in
the state machine and no longer fire events

* Complete migration of persistent notifications

Persistent notifications are no longer stored in
the state machine and no longer fire events

* fixes

* fixes

* fixes

* ws test

* update tests

* update tests

* fix more tests

* fix more tests

* more fixes

* fix

* fix person

* fix person

* keep whitelist

* use singleton
2023-05-25 23:09:13 -04:00
epenet a51cc75f03
Add type hints to core tests (part 2) (#88492) 2023-02-21 09:27:13 +01:00
J. Nick Koston c83ea297b5
Refactor zeroconf task handling (#88204)
* Refactor zeroconf task handling

- Avoid the need to create tasks for most callbacks
- Fixes the untracked task that could get unexpectedly GCed

* be consistant

* be consistant

* fix zeroconf tests

* runtime

* Revert "runtime"

This reverts commit 19e6b61837.

* precalc

* refactor

* tweak

* update tests
2023-02-15 21:44:11 -05:00
epenet c98b4e3204
Add typing to tests with single hass argument (2) (#87675)
* Add typing to tests with single hass argument (2)

* a few more
2023-02-08 08:51:43 +01:00
epenet 59ca7780fa
Add typing to tests with single hass argument (#87631) 2023-02-07 15:01:16 +01:00
Franck Nijhof bfbf9b9751
Adjusts imports in tests to match our relative import rules (#86788) 2023-01-27 12:51:58 +01:00
Franck Nijhof 73c4ac53d2
Enable T20 (flake8-print) to ban use of print statements (#86525)
* Enable T20 (flake8-print) to ban use of print statements

* Make compatible with flake8 config
2023-01-24 14:24:21 +01:00