Commit graph

448 commits

Author SHA1 Message Date
Erik Montnemery
59a690f214
Use ConfigFlow.has_matching_flow to deduplicate homekit_controller flows (#126894) 2024-09-27 13:41:55 +02:00
Erik Montnemery
3c0be47d3c
Add FlowManager.async_has_matching_flow (#126804)
* Add FlowManager.async_flow_has_matching_flow

* Revert changes from the future

* Apply suggested changes to apple_tv config flow

* Rename methods after discussion

* Update homeassistant/data_entry_flow.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Move deduplication functions to config_entries, add tests

* Adjust tests

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-09-27 10:51:36 +02:00
Erik Montnemery
7d61cb1ef5
Remove unignore flow (#126765) 2024-09-25 20:29:14 +02:00
Erik Montnemery
589910b49b
Reinitialize zeroconf discovery flow on config entry removal (#126595) 2024-09-24 13:37:28 +02:00
Erik Montnemery
4a66395d51
Simplify signal_discovered_config_entry_removed job (#126591) 2024-09-24 08:44:11 +02:00
Erik Montnemery
d82bff1bc2
Index config entry discovery_keys by discovery domain (#126563)
* Index config entry discovery_keys by discovery domain

* Add new signal

* Update tests

* Update homeassistant/config_entries.py

Co-authored-by: J. Nick Koston <nick@koston.org>

* Fix imports

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-09-23 21:48:11 +02:00
Erik Montnemery
b2982c18bb
Reinitialize zeroconf discovery flow on unignore (#125753)
* Reinitialize zeroconf discovery flow on unignore

* Adjust tests

* Improve comments

* Fix logic for updating discovery keys

* Add tests

* Use mock_config_flow helper in new config_entries test

* Add discovery_keys attribute to ConfigEntry

* Update zeroconf rediscovery

* Change type of ConfigEntry.discovery_keys

* Update tests

* Fix DiscoveryKey.from_json_dict and add tests

* Fix test

---------

Co-authored-by: J. Nick Koston <nick@koston.org>
2024-09-23 16:49:21 +02:00
Erik Montnemery
252ce2c95b
Improve FlowManager.async_finish_flow docstring (#126178)
* Improve FlowManager.async_finish_flow docstring

* Fix typos
2024-09-18 18:19:13 +02:00
epenet
3536ba43f5
End deprecation setting disabled_by as string (#125646) 2024-09-10 20:39:51 +02:00
epenet
97c55ae6f1
Warn on non-string config entry unique IDs (#125662)
* Warn on non-string config entry unique IDs

* Add comment

* isinstance
2024-09-10 15:30:03 +02:00
G Johansson
436ac72b82
End deprecation setting attributes directly on config entry (#123729)
* End deprecation setting attr directly on config entry

* Update ollama test

* Fix android_tv
2024-09-03 15:56:00 +02:00
Erik Montnemery
9cae786f40
Add ConfigEntries.async_get_loaded (#124705) 2024-08-27 14:20:57 +02:00
J. Nick Koston
91951ed734
Speed up initializing config flows (#124015) 2024-08-16 16:48:03 -05:00
J. Nick Koston
b6de2cd741
Unpack non-performant any expressions in config flow discovery path (#123124) 2024-08-03 17:33:46 -05:00
Robert Resch
ad50136dbd
Add created_at/modified_at to config entries (#122456) 2024-07-29 22:08:46 +02:00
epenet
07c7bb8b2a
Use HOMEASSISTANT_DOMAIN alias for core DOMAIN (#122760) 2024-07-29 13:35:36 +02:00
Marc Mueller
ca55986057
Import Generator from collections.abc (1) (#120914) 2024-07-01 11:51:51 +02:00
Erik Montnemery
471e2a17a2
Improve error messages when config entry is in wrong state (#119591)
* Improve error messages when config entry is in wrong state

* Apply suggestions from code review

Co-authored-by: Joakim Sørensen <ludeeus@ludeeus.dev>

* Adjust tests

---------

Co-authored-by: Joakim Sørensen <ludeeus@ludeeus.dev>
2024-06-14 08:00:36 +02:00
J. Nick Koston
dbd3147c9b
Remove async_late_forward_entry_setups and instead implicitly hold the lock (#119088)
* Refactor config entry forwards to implictly obtain the lock instead of explictly

This is a bit of a tradeoff to not need async_late_forward_entry_setups

The downside is we can no longer detect non-awaited plastform setups
as we will always implicitly obtain the lock instead of explictly.

Note, this PR is incomplete and is only for discussion purposes
at this point

* preen

* cover

* cover

* restore check for non-awaited platform setup

* cleanup

* fix missing word

* make non-awaited test safer
2024-06-12 21:06:11 -04:00
Jake Martin
9bb9792607
Move runtime_data deletion after unload (#119224)
* Move runtime_data deletion after unload.

Doing this before unload means we can't use, eg. the coordinator, during teardown.

* Re-order config entry on unload

* Add test

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-06-10 22:11:07 -04:00
Marc Mueller
fe21e2b8ba
Import Generator from typing_extensions (1) (#118986) 2024-06-06 17:02:13 +02:00
J. Nick Koston
ed0568c655
Ensure config entries are not unloaded while their platforms are setting up (#118767)
* Report non-awaited/non-locked config entry platform forwards

Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.

In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.

If config platform forwards are happening during setup, they should be awaited

If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup

* Report non-awaited/non-locked config entry platform forwards

Its currently possible for config entries to be reloaded while their platforms
are being forwarded if platform forwards are not awaited or done after the
config entry is setup since the lock will not be held in this case.

In https://developers.home-assistant.io/blog/2022/07/08/config_entry_forwards
we advised to await platform forwards to ensure this does not happen, however
for sleeping devices and late discovered devices, platform forwards may happen
later.

If config platform forwards are happening during setup, they should be awaited

If config entry platform forwards are not happening during setup, instead
async_late_forward_entry_setups should be used which will hold the lock to
prevent the config entry from being unloaded while its platforms are being
setup

* run with error on to find them

* cert_exp, hold lock

* cert_exp, hold lock

* shelly async_late_forward_entry_setups

* compact

* compact

* found another

* patch up mobileapp

* patch up hue tests

* patch up smartthings

* fix mqtt

* fix esphome

* zwave_js

* mqtt

* rework

* fixes

* fix mocking

* fix mocking

* do not call async_forward_entry_setup directly

* docstrings

* docstrings

* docstrings

* add comments

* doc strings

* fixed all in core, turn off strict

* coverage

* coverage

* missing

* coverage
2024-06-04 21:34:39 -04:00
Erik Montnemery
35dcda29b9
Use ULID instead of UUID for config entry id and flow ID (#118677) 2024-06-03 10:34:09 +02:00
Jan-Philipp Benecke
88257c9c42
Allow to reconfigure integrations with single_config_entry set (#117939) 2024-05-23 08:41:12 +02:00
J. Nick Koston
13ba8e62a9
Fix race in config entry setup (#117756) 2024-05-20 09:47:47 +02:00
Marc Mueller
4cf0a3f154
Use PEP 695 for function annotations (3) (#117660) 2024-05-18 11:43:32 +02:00
Marc Mueller
87bb7ced79
Use PEP 695 for simple type aliases (#117633) 2024-05-17 14:42:21 +02:00
J. Nick Koston
7871e9279b
Adjust thread safety check messages to point to developer docs (#117392) 2024-05-14 15:20:31 +02:00
Erik Montnemery
0b47bfc823
Add minor version + migration to config entry store (#117350) 2024-05-13 10:16:18 +02:00
Erik Montnemery
b006aadeff
Remove options from FlowResult (#117351) 2024-05-13 10:11:33 +02:00
Erik Montnemery
90ef19a255
Alphabetize some parts of config_entries (#117347) 2024-05-13 09:39:18 +02:00
Erik Montnemery
b09565b4ff
Remove migration of config entry data pre version 0.73 (#117345) 2024-05-13 09:39:04 +02:00
Erik Montnemery
d0c60ab21b
Fix typo and useless default in config_entries (#117346) 2024-05-13 09:26:18 +02:00
Marc Mueller
3434fb70fb
Remove ConfigEntry runtime_data on unload (#117312) 2024-05-12 13:53:22 -04:00
J. Nick Koston
b061e7d1aa
Small speed up to setting up integrations and config entries (#117278)
* Small speed up to setting up integration and config entries

When profiling tests, I noticed many calls to get_running_loop. In the places
where we are already in a coro, pass the existing loop so it does not have to
be looked up. I did not do this for places were we are not in a coro since there
is risk that an integration could be doing a non-thread-safe call and its better
that the code raises when trying to fetch the running loop vs the performance
improvement for these cases.

* fix merge

* missed some
2024-05-11 22:39:20 -04:00
J. Nick Koston
481de8cdc9
Ensure config entry operations are always holding the lock (#117214)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-12 08:20:08 +09:00
J. Nick Koston
daef625985
Speed up init and finish flow (#117226)
Since every flow now has to check for single config entry, change
the check to see if a config entry exists first before calling
the _support_single_config_entry_only since _support_single_config_entry_only
has to load the integration which adds up quite a bit in test runs
2024-05-11 09:47:17 +02:00
J. Nick Koston
52cca26473
Use async_get_loaded_integration in config_entries (#117192) 2024-05-11 10:30:34 +09:00
J. Nick Koston
2e60e09ba2
Ensure config entry setup lock is held when removing a config entry (#117086) 2024-05-11 09:47:26 +09:00
J. Nick Koston
c74c2f3652
Add state check to config entry setup to ensure it cannot be setup twice (#117193) 2024-05-11 07:09:28 +09:00
J. Nick Koston
89049bc022
Fix config entry _async_process_on_unload being called for forwarded platforms (#117084) 2024-05-08 23:59:37 +02:00
Sid
2cc916db6d
Replace pylint broad-except with Ruff BLE001 (#116250) 2024-05-07 14:00:27 +02:00
Marc Mueller
3d700e2b71
Add HassDict implementation (#103844) 2024-05-07 10:53:13 +02:00
Sid
b456d97e65
Replace pylint protected-access with Ruff SLF001 (#115735) 2024-05-06 20:33:26 +02:00
J. Nick Koston
91fa8b50cc
Turn on thread safety checks in async_dispatcher_send (#116867)
* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* Turn on thread safety checks in async_dispatcher_send

We keep seeing issues where async_dispatcher_send is called from
a thread which means we call the callback function on the other
side in the thread as well which usually leads to a crash

* adjust
2024-05-05 16:29:43 -04:00
J. Nick Koston
6cf1c5c1f2
Hold a lock to prevent concurrent setup of config entries (#116482) 2024-04-30 18:47:12 -05:00
Marc Mueller
dace9b32de
Store runtime data inside ConfigEntry (#115669) 2024-04-30 11:29:43 +02:00
J. Nick Koston
164403de20
Add thread safety checks to async_create_task (#116339)
* 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 (#116328) 2024-04-28 08:13:51 -05:00
J. Nick Koston
76639252c9
Make discovery flow tasks background tasks (#116327) 2024-04-28 08:13:37 -05:00