Commit Graph

498 Commits (dev)

Author SHA1 Message Date
Jan Bouwhuis 70b358bca1
Always reload after a successful reauth flow (#116026)
* 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 (#116078) 2024-04-24 11:26:48 +02:00
J. Nick Koston f62a3a7176
Simplify config_entries entity registry filter (#115678) 2024-04-17 09:42:23 -05:00
J. Nick Koston 14b794b0f7
Migrate config entry reauth to use eager_start (#115549) 2024-04-13 18:38:33 -05:00
J. Nick Koston ee535ee611
Ensure test async_create_task eager start behavior matches production (#115517) 2024-04-13 15:58:52 -05:00
J. Nick Koston 08e2b655be
Migrate EntityRegistryDisabledHandler to use async_schedule_reload (#115544)
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 (#115538) 2024-04-13 15:26:41 -05:00
J. Nick Koston 28bdbec14e
Bypass ConfigEntry __setattr__ in __init__ (#115405)
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 (#115169) 2024-04-08 10:07:54 -10:00
Marc Mueller 4e94f11665
Use EventType for entity_registry_updated (#115187) 2024-04-08 08:44:59 -10:00
J. Nick Koston 29bc67234e
Make eager_start default to True for config entry async_create_task (#115047) 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 (#115050) 2024-04-06 10:59:24 -10:00
Marc Mueller 81d682874f
Update typing extensions to 4.11.0 (#114985) 2024-04-06 14:23:32 +02:00
Marc Mueller 816ce116bf
Remove unnecessary functools.cached_property backport (#114239) 2024-04-04 11:24:26 +02:00
J. Nick Koston ef047707d9
Simplify config entry cache clear (#114691)
same as #113136 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 (#114695)
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 (#114437)
* 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 (#106305)
* 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] (#114298) 2024-03-27 14:25:02 +01:00
Marc Mueller d0ecad78ac
Revert "Update typing-extensions to 4.11.0rc1 (#114116)" (#114216) 2024-03-25 20:44:57 -10: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
Marc Mueller 188dbfbd2a
Update typing-extensions to 4.11.0rc1 (#114116) 2024-03-25 11:27:47 +01:00
J. Nick Koston d0dc820ced
Cancel config entry setup retry at shutdown (#114124) 2024-03-24 09:09:24 -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
J. Nick Koston 3b66328591
Add a fast path for async_get_platform (#113917) 2024-03-21 09:34:33 +01: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 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 6a6f3d46a9
Create config entry async_on_unload tasks eagerly (#113626) 2024-03-16 14:43:49 -10:00
J. Nick Koston 6e3e2d1693
Shutdown config entry manager immediately at the stop event (#113632) 2024-03-16 13:39:31 -10: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
J. Nick Koston e347096ef5
Add a task name to the config entry retry tasks (#113188) 2024-03-12 14:19:22 -10: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
Erik Montnemery 82efb3d35b
Make FlowResult a generic type (#111952) 2024-03-07 12:41:14 +01:00
Erik Montnemery 3d3e9900c3
Add TypeVar default for FlowResult (#112345)
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 (#112291)
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 (#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 2c179dc5fb
Reduce some linear searches to cleanup the device registry (#112277)
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 (#112141)
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 (#111932)
* 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 (#108794)
* 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 (#111814)
* 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 (#111800)
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 #111796
2024-02-29 15:47:36 +01:00
J. Nick Koston b9718fe2e9
Avoid tracking tasks that finish right away (#111690) 2024-02-27 19:09:34 -10:00
Erik Montnemery fc4b18b907
Return FlowResultType.ABORT when violating single_config_entry (#111637)
* Return FlowResultType.ABORT when violating single_config_entry

* Fix translations

* Fix tests
2024-02-27 18:28:19 +01:00
Erik Montnemery 6ccf7dea32
Always allow ignore and unignore flows for single config entry integrations (#111631)
* Always allow ignore and unignore flows for single config entry integrations

* Update tests/test_config_entries.py

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

---------

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-02-27 15:47:56 +01:00
J. Nick Koston 7d9fa2f407
Load config entry platforms eagerly (#111498)
We can avoid one event loop iteration to start the tasks here.
2024-02-26 23:55:41 -05: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
Jan-Philipp Benecke baf84b6fba
Add `single_config_entry` manifest option (#109505)
* Allow setting if we support multiple config entries in config flow

* Move property to config flow instead of flow handler

* Move marking an integration as single instance only to manifest

* Revert line remove

* Avoid init a config flow or adding a new entry on a single instance with an entry

* Revert changes in test

* Process code review comments

* Apply code review suggestion
2024-02-26 19:00:33 +01:00
J. Nick Koston 4624c859e1
Use discovery flow helper for hardware integrations (#111437)
* Use discovery flow helper for hardware integrations

The discovery flow helper defers loading discovered integrations until after startup
to improve startup reliability.

* Use discovery flow helper for hardware integrations

The discovery flow helper defers loading discovered integrations until after startup
to improve startup reliability. Since hardware was not listed in as a
discovery integration, the notification for new discoveries was missing.
2024-02-26 12:04:33 -05:00
J. Nick Koston 67e356904b
Add support for eager tasks (#111425)
* Add support for eager tasks

python 3.12 supports eager tasks

reading:
https://docs.python.org/3/library/asyncio-task.html#eager-task-factory
https://github.com/python/cpython/issues/97696

There are lots of places were we are unlikely to suspend, but we might
suspend so creating a task makes sense

* reduce

* revert entity

* revert

* coverage

* coverage

* coverage

* coverage

* fix test
2024-02-26 11:36:46 -05:00
Aidan Timson 9f77e275e9
Add title to reauthenticate integration issue (#111275)
* Add title to reauthenticate integration issue

* Fix translation placeholder in test

* Update translation placeholders in test_init.py

* Update integration reauthentication message

* Update string
2024-02-26 08:19:37 -05:00
J. Nick Koston ff0e0b3e77
Convert debouncer async_shutdown to be a normal function (#111257)
* Convert debouncer async_shutdown to be a normal function

nothing was being awaited here and the shutdown call was only used
in integrations marked internal and other internals. Its possible
that a custom component might have been using the method but it
seemed uncommon enough that it did not warrent marking as a breaking
change. The update coordinator is no longer awaiting anything in
async_shutdown either now but it seemed likely that this use
would get subclassed.

* fix
2024-02-24 08:37:33 +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 490c03d248
Add async_schedule_call to the Debouncer (#111051) 2024-02-21 00:09:45 -06:00
J. Nick Koston 2f2cdedddd
Avoid creating multiple tasks for config entry init (#110899) 2024-02-20 21:57:36 -05:00
J. Nick Koston 94e372a345
Make ConfigEntry.async_shutdown a callback (#111027)
Nothing needed to be awaited here and this generated a task per config
entry at shutdown
2024-02-20 21:38:24 -05:00
J. Nick Koston ae49b3a274
Add async_schedule_reload helper to the ConfigEntries manager (#110912)
* Add async_schedule_reload helper to the ConfigEntries manager

We have cases where the the setup retry kicks in right before
the reload happens causing the reload to fail with
OperationNotAllowed. The async_schedule_reload will
cancel the setup retry before the async_reload task
is created to avoid this problem.

I updated a few integrations that were most likely
to have this problem. Future PRs will do a more
extensive audit

* coverage

* revert for now since this needs more refactoring in a followup

* cover

* cleanup and fixes
2024-02-20 02:14:45 +01:00
J. Nick Koston b35490404a
Make EntityRegistryDisabledHandler._handle_entry_updated a callback (#110966) 2024-02-19 14:44:57 -06: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
J. Nick Koston 0a01161cdd
Cache JSON representation of ConfigEntry objects (#110823)
* Cache JSON representation of ConfigEntry objects

* fix recursive set

* tweak

* adjust

* order
2024-02-17 20:52:39 -05:00
J. Nick Koston 094fd3d918
Simplify ConfigFlow._async_current_entries (#110799)
async_entries supports the flags needed for this function so we
can now hand it off instead
2024-02-17 18:04:27 +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
J. Nick Koston d449eadac3
Guard ConfigEntry from being mutated externally without using the built-in interfaces (#110023)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
2024-02-16 10:15:05 -06:00
J. Nick Koston 4c11371898
Adjust ConfigEntry.async_setup comments to be more clear (#110726) 2024-02-16 10:13:35 -06:00
J. Nick Koston 01c3205635
Small performance improvements to config entry setup retry (#110448)
* Small performance improvements to config entry setup retry

- cache some properties that never change
- avoid loader.async_get_integration when we already have it
- avoid multiple integration.domain checks

* tweaks
2024-02-13 13:28:52 +01:00
J. Nick Koston 6e134b325d
Make ConfigEntryItems responsible for updating unique ids (#110018)
* Make ConfigEntryItems responsible for updating unique ids

* Make ConfigEntryItems responsible for updating unique ids

* Make ConfigEntryItems responsible for updating unique ids

* Make ConfigEntryItems responsible for updating unique ids

* Make ConfigEntryItems responsible for updating unique ids
2024-02-09 08:51:02 -05:00
Erik Montnemery 793b6aa97d
Allow passing version to ConfigEntry.async_update_entry (#110077)
Allow passing minor_version and version to ConfigEntry.async_update_entry
2024-02-09 10:10:25 +01:00
Erik Montnemery 2f15053311
Don't blow up if config entries have unhashable unique IDs (#109966)
* Don't blow up if config entries have unhashable unique IDs

* Add test

* Add comment on when we remove the guard

* Don't stringify hashable non string unique_id
2024-02-08 15:39:01 +01:00
Marc Mueller 5de76c0be0
Include exception when reraising inside except (#109706) 2024-02-06 12:17:39 +01:00
Erik Montnemery ffdcdaf43b
Create issues for reauth flows (#109105) 2024-01-31 15:05:52 +01:00
J. Nick Koston dff5e45761
Small speed up to listing config entries in the websocket api (#108892) 2024-01-25 20:20:19 -10:00
Jan-Philipp Benecke 0b79504cf0
Extend config entry update/abort helper to also update unique id (#108681)
* Extend config entry update/abort helper to also update unique id

* Move kwarg to end

* Make additionals kwargs only
2024-01-22 23:01:55 +01:00
Jan-Philipp Benecke 988d72b8b6
Add helper function to update and reload config entry to config flow (#108034)
* Add helper function to update and reload config entry to config flow

* Use async_create_task

* Remove await

* Reload only when update & add task name

* Rename function
2024-01-22 17:40:20 +01:00
J. Nick Koston 3649cb96de
Refactor config entry storage and index (#107590) 2024-01-13 10:34:15 -10:00
J. Nick Koston 4b7a313ece
Use identity checks for CoreState (#107846)
Some of the checks used ==, and some used is. Switch
everything to is as its faster
2024-01-12 10:21:26 +01:00
J. Nick Koston b2f7fd12a2
Add comment to ConfigEntry.async_setup about race safety (#107756) 2024-01-10 13:03:09 -10:00
Erik Montnemery 6908497c3d
Add minor version to config entries (#105479) 2023-12-12 08:44:35 +01:00
Jan Bouwhuis 487ff8cd7f
Rename ex to exc as name for exceptions (#104479) 2023-11-25 08:30:18 +01:00
J. Nick Koston 9b27552238
Fix race in starting reauth flows (#103130) 2023-10-31 12:38:05 -05:00
Franck Nijhof 6853d54050
Remove logging of retrying config entry warning (#101483) 2023-10-05 22:12:01 +02:00
J. Nick Koston a03ad87cfb
Avoid ConfigEntry lookups in hass.config_entries.async_entries for domain index (#100598) 2023-09-20 18:43:15 +02:00
J. Nick Koston 1d5905b591
Use is for UNDEFINED check in async_update_entry (#100599) 2023-09-20 01:08:32 +02:00
J. Nick Koston e3f228ea52
Switch config_entries to use loop.create_future() (#100011) 2023-09-09 17:34:49 -05:00
J. Nick Koston e5ebba0753
Fix module check in _async_get_flow_handler (#99509)
We should have been checking for the module in hass.data[DATA_COMPONENTS]
and not hass.config.components as the check was ineffective if there were
no existing integrations instances for the domain which is the case for
discovery or when the integration is ignored
2023-09-04 14:19:10 -04:00
J. Nick Koston b8f8cd1797
Reduce overhead to retry config entry setup (#99471) 2023-09-02 16:46:53 -05:00
J. Nick Koston 99e97782b6
Improve performance of abort_entries_match (#98932)
* Improve performance of abort_entries_match

In #90406 a ChainMap was added which called __iter__
and __contains__ which ends up creating temp dicts
for matching

174e9da083/Lib/collections/__init__.py (L1022)

We can avoid this by removing the ChainMap since there
are only two mappings to match on.

This also means options no longer obscures data

* adjust comment
2023-08-24 15:34:45 +02:00
Erik Montnemery d282ba6bac
Use a single WS command for group preview (#98903)
* Use a single WS command for group preview

* Fix tests
2023-08-24 11:59:24 +02:00
Erik Montnemery b885dfa5a8
Add preview to sensor group config and option flows (#83638) 2023-08-22 10:29:16 +02:00
J. Nick Koston 1adfa6bbeb
Reduce overhead to start a config entry flow by optimizing fetching the handler (#97883) 2023-08-06 20:25:03 -10:00
Franck Nijhof 30058297cf
Migrate backported StrEnum to built-in StrEnum (#97101) 2023-07-23 23:19:24 +02:00
Marc Mueller 77f38e33e5
Import names from typing instead of typing_extensions [3.11] (#97065) 2023-07-22 17:03:44 -05:00
J. Nick Koston 9fba6870fe
Fix task leak on config entry unload/retry (#96981)
Since the task was added to self._tasks without a `task.add_done_callback(self._tasks.remove)`
each unload/retry would leak a new set of tasks
2023-07-20 21:00:07 -04:00
J. Nick Koston 6bb81b862c
Add a message to the config entry cancel call (#96925) 2023-07-19 19:22:38 -05:00
J. Nick Koston 085eebc903
Make async_set_state in ConfigEntry a protected method (#96727)
I added this in #77803 but I never designed it to be called
externally. External usage may break at any time because the
class is not designed for this. I should have made it protected
in the original PR but I did not think it would get called
externally (my mistake)
2023-07-17 08:58:12 +02:00
Paulus Schoutsen 0f725a24bd
Remove the weak ref for tracking update listeners (#95798) 2023-07-03 13:56:21 -05:00
J. Nick Koston 34b725bb99
Debounce discoveries to improve event loop stability at the started event (#94690)
* Debounce discoveries to improve event loop stability at the started event

The first one is immediate and anything that fires within the next
second will be debounced to only happen once every second

* fix mock
2023-06-15 22:15:07 -04:00
J. Nick Koston 9e666ae0c0
Reduce in progress flow matching overhead (#94403)
* Reduce config flow matching overhead

Much of the config flow matching is happening on the context data
after converting via a series of functions. Avoid the conversions
by passing the context matcher deeper into the stack so only
relvant entries need to be processed.

The goal is to reduce the overhead and reduce the chance
the event loop falls behind at the started event when
all the discoveries are processed

* Reduce config flow matching overhead

Much of the config flow matching is happening on the context data
after converting via a series of functions. Avoid the conversions
by passing the context matcher deeper into the stack so only
relvant entries need to be processed.

The goal is to reduce the overhead and reduce the chance
the event loop falls behind at the started event when
all the discoveries are processed

* Reduce config flow matching overhead

Much of the config flow matching is happening on the context data
after converting via a series of functions. Avoid the conversions
by passing the context matcher deeper into the stack so only
relvant entries need to be processed.

The goal is to reduce the overhead and reduce the chance
the event loop falls behind at the started event when
all the discoveries are processed

* augment cover
2023-06-11 10:41:38 +02:00
J. Nick Koston cf69da40f3
Only check support_entry_unload/support_remove_from_device once (#92041) 2023-04-26 10:23:18 +02:00
J. Nick Koston 739963b5ee
Remove deprecated async_setup_platforms (#91929) 2023-04-23 22:38:35 -05:00
epenet 3364f0fce2
Allow config entries unload action to be coroutine (#91531)
* Allow config entries unload action to be coroutine

* Adjust comment
2023-04-17 08:41:25 -04:00
epenet a061f56833
Fix lingering timer in EntityRegistryDisabledHandler (#91376)
Mark EntityRegistryDisabledHandler as cancellable
2023-04-14 06:37:49 +02:00
epenet 611d4135fd
Add ComponentProtocol to improve type checking (#90586) 2023-03-31 14:19:58 -04:00
epenet f7925763a4
Make abort_entries_match available in options flow (#90406)
* Make abort_entries_match available in options flow

* Add tests

* Exclude ignore entries and add test

* Move to OptionsFlow

* Adjust tests

* Use mock_config_flow

* Use AbortFlow

* Remove duplicate code
2023-03-29 17:20:51 +02:00
Erik Montnemery 3931e11fd9
Try to load integration before starting option flow (#90111)
* Try to load integration before starting option flow

* Adjust tests
2023-03-22 20:10:10 +01:00
Jesse Moody d7de23fa65
Adjust eventloop -> event loop spelling (#89931)
eventloop -> event loop spelling
2023-03-19 21:53:21 +01: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
J. Nick Koston f8934175cb
Prevent integrations from retrying setup once shutdown has started (#88818)
* Prevent integrations from retrying setup once shutdown has started

* coverage
2023-02-26 22:01:02 -05:00
Paulus Schoutsen 3a32d2bdcb
Add background tasks to config entries (#88335)
* Use a set for config entries task tracking

* Allow adding background tasks to config entries

* Add tests for config entry add tasks

* Update docstrings on core create task

* Migrate roon and august

* Use in more places

* Guard for None
2023-02-17 13:50:05 -05:00
Marc Mueller 342b406dc0
Add Self typing (1) [mypy 1.0] (#87598) 2023-02-06 22:29:47 -06:00
J. Nick Koston 7ddb467ba6
Increase async_setup_platforms deprecation logging to warning (#86582) 2023-01-25 14:38:26 +01:00
Ville Skyttä 5f0adfe6e4
Add missing config flow abort strings (#86180)
* Add missing `already_configured` and `already_in_progress` abort strings

* Note required strings.json entries in config_entries aborting functions
2023-01-24 08:59:32 +02:00
Marc Mueller 6397138589
Update Optional typing (1) [Py310] (#86417)
Co-authored-by: Franck Nijhof <git@frenck.dev>
2023-01-23 09:56:10 +01:00
Franck Nijhof 79b52a2b41
Stricter pylint message control (#86154) 2023-01-20 13:47:55 +01: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
Erik Montnemery 3cd6bd87a7
Remove config entry specifics from FlowManager (#85565) 2023-01-17 15:26:17 +01:00
Franck Nijhof 64c2340fab
Core code styling improvements (#85963) 2023-01-15 23:00:51 +01:00
Erik Montnemery 22dbbd4b71
Revert "Disable sky connect config entry if USB stick is not plugged in" (#85103) 2023-01-04 11:33:16 +01:00
Erik Montnemery 472c23d35f
Disable sky connect config entry if USB stick is not plugged in (#84975)
* Disable sky connect config entry if USB stick is not plugged in

* Remove debug stuff
2023-01-02 22:24:59 +01:00
J. Nick Koston 4296f227cf
Fix thundering heard in setup_again when there are many integrations (#84670) 2022-12-27 15:59:42 -10: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 bf4c399b19
Improve data entry flow typing (#84030) 2022-12-15 12:41:20 +01:00
Erik Montnemery cc132bfad6
Make it optional to provide a title when finishing a FlowHandler (#83534)
* Make it optional to provide a title when finishing a FlowHandler

* Make ConfigEntry.title a str

* Revert changes in ConfigFlow

* Adjust tests
2022-12-09 10:24:08 +01:00
Michael 444ad52757
Fix info message in config_entries handle_reload (#82798) 2022-11-27 14:34:01 -05:00
Franck Nijhof c715035016
Add support for raising ConfigEntryError (#82689) 2022-11-25 11:33:03 +01:00
epenet e7d4f745ec
Expose config_entry and options as properties (#82691)
Expose config_entry and options as a property
2022-11-25 11:13:44 +01:00
epenet 4c38a5d773
Add OptionsFlow helper class (#82531)
* Add OptionsFlow helper classes

* More integrations

* Adjust SchemaOptionsFlowHandler

* Use single class

* Simplify access to options

* Reduce PR

* Make _options private

* Add test
2022-11-24 12:18:09 +01:00
Jan Bouwhuis c720742ec9
Revert #81771 (wait_for_states) and #81801 (late review) (#82085)
* Revert "Address late review of config entry wait for states tests (#81801)"

This reverts commit 12d76a8a4f.

* Revert "Implement ConfigEntry async_wait_for_states (#81771)"

This reverts commit 3cc9ecf1dc.
2022-11-18 17:16:03 +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
Aaron Bach adf84b0c62
Add `async_get_active_reauth_flows` helper for config entries (#81881)
* Add `async_get_active_reauth_flows` helper for config entries

* Code review

* Code review + tests
2022-11-09 15:36:50 -07:00
Jan Bouwhuis 3cc9ecf1dc
Implement ConfigEntry async_wait_for_states (#81771)
* Implement async_wait_for_states

* stale docstr, remove hints

* Assert return states for tests
2022-11-08 17:18:40 +01:00
J. Nick Koston 4d1fa42a3c
Use more efficient async_progress_by_handler call in async_start_reauth (#81757) 2022-11-08 11:20:54 +01:00
J. Nick Koston c2c26e2608
Fix check for duplicate config entry reauth when context is passed or augmented (#81753)
fixes https://github.com/home-assistant/core/issues/77578
2022-11-07 21:19:57 -06:00
J. Nick Koston 74f7ae409b
Add a helpful message to the config_entries.OperationNotAllowed exception (#78631)
We only expect this exception to be raised as a result of an
implementation problem. When it is raised during production
it is currently hard to trace down why its happening

See #75835
2022-09-17 20:52:28 +03:00
J. Nick Koston 016a59ac94
Add support for subscribing to config entry changes (#77803) 2022-09-04 22:57:43 -05:00
Zach Berger ebbff7b60e
Add Awair Local API support (#75535) 2022-08-11 09:01:35 -04:00
Jc2k a0adfb9e62
Fix serialization of Xiaomi BLE reauth flow (#76095)
* Use data instead of context to fix serialisation bug

* Test change to async_start_reauth
2022-08-02 21:38:38 +01:00
Jc2k f043203b56
Add optional context parameter to async_start_reauth (#76077) 2022-08-02 18:20:37 +02:00
J. Nick Koston 80a9659524
Update to bleak 0.15 (#75941) 2022-07-29 17:53:33 -07:00
Marc Mueller d09fff595c
Rename existing TypeVars referencing Self type (#75473) 2022-07-20 03:03:22 +02:00
J. Nick Koston 32311f240b
Avoid converting discovery_info dataclasses to dict that will be thrown away in config flows (#75451)
* Avoid converting BluetoothServiceInfo to a dict for default discovery

Fixes
```
2022-07-19 09:46:48.303 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/helpers/discovery_flow.py", line 74, in _async_process_pending_flows
    await gather_with_concurrency(
  File "/Users/bdraco/home-assistant/homeassistant/util/async_.py", line 201, in gather_with_concurrency
    return await gather(
  File "/Users/bdraco/home-assistant/homeassistant/util/async_.py", line 199, in sem_task
    return await task
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 222, in async_init
    flow, result = await task
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 249, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 1484, in async_step_bluetooth
    return await self.async_step_discovery(dataclasses.asdict(discovery_info))
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1239, in asdict
    return _asdict_inner(obj, dict_factory)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1246, in _asdict_inner
    value = _asdict_inner(getattr(obj, f.name), dict_factory)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1280, in _asdict_inner
    return copy.deepcopy(obj)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: Cannot pickle Objective-C objects
```

* Avoid converting BluetoothServiceInfo to a dict for default discovery

Fixes
```
2022-07-19 09:46:48.303 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/Users/bdraco/home-assistant/homeassistant/helpers/discovery_flow.py", line 74, in _async_process_pending_flows
    await gather_with_concurrency(
  File "/Users/bdraco/home-assistant/homeassistant/util/async_.py", line 201, in gather_with_concurrency
    return await gather(
  File "/Users/bdraco/home-assistant/homeassistant/util/async_.py", line 199, in sem_task
    return await task
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 222, in async_init
    flow, result = await task
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 249, in _async_init
    result = await self._async_handle_step(flow, flow.init_step, data, init_done)
  File "/Users/bdraco/home-assistant/homeassistant/data_entry_flow.py", line 359, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/Users/bdraco/home-assistant/homeassistant/config_entries.py", line 1484, in async_step_bluetooth
    return await self.async_step_discovery(dataclasses.asdict(discovery_info))
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1239, in asdict
    return _asdict_inner(obj, dict_factory)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1246, in _asdict_inner
    value = _asdict_inner(getattr(obj, f.name), dict_factory)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/dataclasses.py", line 1280, in _asdict_inner
    return copy.deepcopy(obj)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 172, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 271, in _reconstruct
    state = deepcopy(state, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 146, in deepcopy
    y = copier(x, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 231, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/opt/homebrew/Cellar/python@3.10/3.10.5/Frameworks/Python.framework/Versions/3.10/lib/python3.10/copy.py", line 161, in deepcopy
    rv = reductor(4)
TypeError: Cannot pickle Objective-C objects
```
2022-07-19 18:50:30 +02:00
J. Nick Koston fde3489e86
Relocate BluetoothServiceInfo to helpers.service_info (#75195) 2022-07-14 11:36:54 -07:00
J. Nick Koston 666f715e76
Avoid importing MQTT into core for ServiceInfo dataclass (#74418)
* Avoid importing MQTT into core for discovery dataclass

Likely fixes #73863

* relo

* adjust

* rename

* rename

* rename

* adjust missed imports

* drop compat

* fix conflict correctly

* Update homeassistant/helpers/config_entry_flow.py

* fix black from trying to fix the conflict in github
2022-07-14 11:09:09 -05:00
epenet 16900dcef1
Make Store a generic class (#74617) 2022-07-09 22:32:57 +02:00
J. Nick Koston cd03c49fc2
Wait for config entry platform forwards (#73806) 2022-07-09 17:27:42 +02:00
J. Nick Koston a697672944
Add bluetooth integration (#74653)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2022-07-08 18:55:31 -05:00