Commit graph

148 commits

Author SHA1 Message Date
Marc Mueller e0f5559c8f
Improve generic event typing [EventComponentLoaded] (#114739) 2024-04-06 14:18:03 +02:00
J. Nick Koston 17da077c74
Avoid trying to load platform that are known to not exist in async_prepare_setup_platform (#114659) 2024-04-02 11:22:40 -10:00
Sid 6587ee20db
Enable Ruff TRY300 (#114437)
* Enable Ruff TRY300

* Update validation.py

* Address review comments
2024-03-30 10:37:59 +01: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 e8cb6a8e29
Optimize loading of translations (#114089) 2024-03-23 22:22:09 -10:00
J. Nick Koston 4f18f0d902
Fix setup timings when config entry platform loads are not awaited (#113959)
* 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
Erik Montnemery d31124d5d4
Avoid creating unneeded Context and Event objects when firing events (#113798)
* 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 879e5bc961
Only wait for import flows in setup of there is a config flow (#113780) 2024-03-19 10:38:27 -10: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
J. Nick Koston 5e94858821
Migrate _async_when_setup to use eager_start (#112872)
This one does not make much difference, but its a lot
easier to do it now instead of in the future
2024-03-11 15:02:35 -04:00
Marc Mueller de886d8c49
Update EventBus listen type signatures (#112760) 2024-03-08 21:57:23 +01:00
Marc Mueller cef20506dc
Replace EventType with Event [missing] (#112753) 2024-03-08 21:56:42 +01:00
Marc Mueller 19ab3d6daf
Add empty line after module docstring [helpers + other] (#112707) 2024-03-08 10:36:11 -05:00
J. Nick Koston d6cbadba3e
Ensure setup loads top level component before platforms (#112057) 2024-03-03 11:42:16 -10:00
J. Nick Koston 9af12a0639
Avoid calling async_get_component twice for each component being setup (#112096)
We already have the component so we can pass it to
async_process_component_config to avoid having to
look it up again
2024-03-03 12:48:07 -05:00
J. Nick Koston 6abb8ae273
Migrate setup to use eager tasks (#111619) 2024-02-27 12:43:32 -10: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 dd80157dc7
Load translations at setup time if they were not loaded at bootstrap (#110921) 2024-02-24 11:31:25 -10:00
Marc Mueller 5f8ef37f2d
Update pylint to 3.0.4 (#111229)
* Update pylint to 3.0.4

* Use yield from

* Remove unnecessary pylint disable comments
2024-02-23 23:46:00 +01:00
J. Nick Koston 2ef71289b9
Avoid creating tasks for dependencies already being setup (#111034)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-02-22 12:34:46 -10:00
J. Nick Koston 4bc28489c5
Improve performance of waiting for after dependencies and device config entries (#110902)
To wait for after dependencies we created a task to wait an asyncio.Event object,
instead of using an Event we can use an asyncio.Future instead and avoid the need
for a task wrapper
2024-02-19 10:28:50 +01:00
Marc Mueller 85864e77ac
Partially revert setup typing update (#110901) 2024-02-19 00:36:47 +01:00
J. Nick Koston 314123e0ab
Avoid creating two tasks to setup components at startup (#110828) 2024-02-18 14:17:41 -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
J. Nick Koston 0d6f4058ca
Add typing for EVENT_COMPONENT_LOADED (#110812) 2024-02-17 23:03:52 +01:00
J. Nick Koston b8143a7944
Improve performance of _async_when_setup (#110791)
* Improve performance of _async_when_setup

Use an event filter to avoid creating a task until the
filter matches

* Improve performance of _async_when_setup

Use an event filter to avoid creating a task until the
filter matches
2024-02-17 17:46:06 +01:00
J. Nick Koston 0bf95df4d6
Avoid creating tasks to setup ignored and disabled config entries (#110756)
* Avoid creating tasks to setup ignored and disabled config entries

* lint
2024-02-17 10:34:03 +01:00
Marc Mueller cd0ee98dba
Use builtin TimeoutError [core + helpers] (#109684) 2024-02-05 12:09:54 +01:00
Erik Montnemery 5e79cd8715
Remove file/line annotations after config has been validated (#107139) 2024-01-14 11:07:39 +01:00
Erik Montnemery 25bea91683
Use modern platform path when reporting platform config errors (#104238)
* Use modern platform path when reporting platform config errors

* Update tests

* Address review comment

* Explicitly pass platform domain to log helpers

* Revert overly complicated changes

* Try a simpler solution
2023-12-05 15:06:13 +01:00
Erik Montnemery 84e74e4c74
Reverse component path (#104087)
* Reverse component path

* Update translations helper

* Fix

* Revert incorrect change of PLATFORM_FORMAT

* Fix use of PLATFORM_FORMAT in tts

* Fix ios
2023-12-05 08:43:58 +01:00
Jan Bouwhuis af71c2bb45
Raise and suppress stack trace when reloading yaml fails (#102410)
* Allow async_integration_yaml_config to raise

* Docstr - split check

* Implement as wrapper, return dataclass

* Fix setup error handling

* Fix reload test mock

* Move log_messages to error handler

* Remove unreachable code

* Remove config test helper

* Refactor and ensure notifications during setup

* Remove redundat error, adjust tests notifications

* Fix patch

* Apply suggestions from code review

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

* Follow up comments

* Add call_back decorator

* Split long lines

* Update exception abbreviations

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2023-11-24 17:34:45 +01:00
Erik Montnemery 67e25dc0bf
Quote domain name in setup logs (#104239)
* Quote domain name in setup logs

* Update tests
2023-11-20 12:55:16 +01:00
J. Nick Koston a027a01535
Log a traceback when importing a component fails (#94778)
`2023-06-17 12:44:37.961 ERROR (MainThread) [homeassistant.setup] Setup failed for switchbot: Unable to import component: cannot import name DEFAULT_CIPHERS from urllib3.util.ssl_ (/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/urllib3/util/ssl_.py)` is not very helpful as it does not show which module tried to import.

adding a traceback makes it more obvious, and since ImportError is usually not something
the user can easily solve, it makes issue reports much more helpful

```
DEFAULT_CIPHERS from urllib3.util.ssl_ (/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/urllib3/util/ssl_.py)
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/setup.py", line 213, in _async_setup_component
    component = integration.get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/bdraco/home-assistant/homeassistant/loader.py", line 813, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1149, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 690, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 940, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/Users/bdraco/home-assistant/homeassistant/components/switchbot/__init__.py", line 5, in <module>
    import switchbot
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/switchbot/__init__.py", line 22, in <module>
    from .devices.lock import SwitchbotLock
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/switchbot/devices/lock.py", line 12, in <module>
    import boto3
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/boto3/__init__.py", line 16, in <module>
    from boto3.session import Session
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/boto3/session.py", line 17, in <module>
    import botocore.session
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/session.py", line 29, in <module>
    import botocore.credentials
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/credentials.py", line 34, in <module>
    from botocore.config import Config
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/config.py", line 16, in <module>
    from botocore.endpoint import DEFAULT_TIMEOUT, MAX_POOL_CONNECTIONS
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/endpoint.py", line 22, in <module>
    from botocore.awsrequest import create_request_object
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/awsrequest.py", line 24, in <module>
    import botocore.utils
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/utils.py", line 32, in <module>
    import botocore.httpsession
  File "/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/botocore/httpsession.py", line 10, in <module>
    from urllib3.util.ssl_ import (
ImportError: cannot import name DEFAULT_CIPHERS from urllib3.util.ssl_ (/Users/bdraco/home-assistant/venv/lib/python3.11/site-packages/urllib3/util/ssl_.py)
```
2023-06-19 13:10:39 +02:00
Franck Nijhof 6db1fbf480
Fix repair issue about no yaml for config entries (#94271) 2023-06-08 18:22:34 +02:00
Erik Montnemery c1c319d4d1
Rename cv.no_yaml_config_schema to cv.config_entry_only_config_schema (#93908)
* Rename cv.no_yaml_config_schema to cv.config_entry_only_config_schema

* ✏️
2023-06-01 13:15:48 +02:00
Erik Montnemery ef4dea07cd
Improve no-yaml warning (#93851) 2023-05-31 10:11:02 +02:00
G Johansson 3f3b833034
Add issue when integration key YAML not supported (#93807)
* Add issue when integration key YAML not supported

* Fix feedback

* Fix review

* Update homeassistant/components/homeassistant/strings.json

Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>

---------

Co-authored-by: Franck Nijhof <frenck@frenck.nl>
Co-authored-by: c0ffeeca7 <38767475+c0ffeeca7@users.noreply.github.com>
2023-05-31 09:56:33 +02:00
Erik Montnemery 8b662dc94f
Detect attempt to setup config entry integration via YAML (#93589) 2023-05-29 21:01:47 +02:00
Jan Bouwhuis da26b0a930
Ensure dependencies are awaited correctly when setting up integrations (#91454)
* Do not wait

* Correct tests

* Manage after dependencies stage 1

* test bootstrap dependencies

* Assert log the dependenciy is waited for

* Improve docstrings

* Assert outside callback

* Patch async_get_integrations

* Revert changes made to snips integration

* Undo changes to mqtt_statestream
2023-04-21 08:33:50 +02:00
epenet 611d4135fd
Add ComponentProtocol to improve type checking (#90586) 2023-03-31 14:19:58 -04:00
J. Nick Koston 4ce36366c3
Add names to the config entry setup and shutdown tasks (#89309)
* name the entry setup tasks

* name a few more tasks

* Update homeassistant/config_entries.py

* Update homeassistant/setup.py
2023-03-08 10:19:36 -05:00
J. Nick Koston 11681f3f31
Pass a helpful name when creating common asyncio tasks in core (#89171) 2023-03-05 12:46:02 +01:00
Erik Montnemery 2c2489284b
Catch CancelledError when setting up components (#88635)
* Catch CancelledError when setting up components

* Catch CancelledError when setting up components

* Also catch SystemExit
2023-02-27 09:29:14 -05:00
Erik Montnemery f17a829bd8
Only wait for import flows to initialize at setup (#86106)
* Only wait for import flows to initialize at setup

* Update hassio tests

* Update hassio tests

* Apply suggestions from code review

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

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2023-01-18 10:44:18 +01:00
Franck Nijhof 64c2340fab
Core code styling improvements (#85963) 2023-01-15 23:00:51 +01:00
Franck Nijhof b0cee0bc46
String formatting and max line length - Part 1 (#84390)
Co-authored-by: Erik Montnemery <erik@montnemery.com>
2022-12-22 10:12:50 +01:00
Erik Montnemery 1a274adc28
Add config_entries.async_wait_component (#76980)
Co-authored-by: thecode <levyshay1@gmail.com>
2022-11-17 21:52:57 +01:00
Aarni Koskela 8038485ca4
Use partition instead of split where possible in core (#81806) 2022-11-15 21:45:48 +01:00
Erik Montnemery 408069cb0c
Always install requirements of after_dependencies (#79094) 2022-09-26 09:59:01 -04:00