Commit Graph

301 Commits

Author SHA1 Message Date
epenet
99eb466223 Add updates argument to update_reload_and_abort helper (#127781)
* Add updates argument to update_reload_and_abort helper

* Also apply to airvisual_pro

* Rename argument

* docstring

* Use modern syntax

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

* Apply suggestion

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

* Apply suggestion

* Docstring

---------

Co-authored-by: Erik Montnemery <erik@montnemery.com>
2024-10-09 07:47:18 +02:00
epenet
5836a85340 Prevent async_create_entry from reauth/reconfigure flows (#127527)
* Prevent `async_create_entry` from reauth/reconfigure flows

* Adjust message

* Don't raise just yet

* Adjust message

* Fix string

* Remove invalid comment

* Add parameter

* Use count parameter

* Remove another branching
2024-10-08 15:19:58 +02:00
epenet
4e15556eeb Cleanup unused variable in tests (#127930) 2024-10-08 15:14:23 +02:00
Erik Montnemery
0c0ff855b1 Warn when async_update_entry creates a unique_id collision (#127929) 2024-10-08 14:42:41 +02:00
epenet
4478f64002 Remove dead reconfigure code (#127398)
* Remove dead reconfigure code

* Adjust

* Start cleaning up test

* Prevent duplicate flows

* Add missing string

* Adjust two more tests

* Only filter out reauth flows

* Update strings.json

* Update config_entries.py

* Adjust tests

* Remove all checks - but add comment in tests

* Simplify PR
2024-10-08 13:35:04 +02:00
epenet
2c664efb3c Add new helper for matching reauth/reconfigure config flows (#127565) 2024-10-08 10:07:36 +02:00
epenet
8c0e96e6e6 Extend update_entry_and_reload tests (#127776) 2024-10-07 11:23:48 +02:00
epenet
c87a2ca335 Add default reconfigure reason in update_reload_and_abort (#127756)
* Add default reconfigure reason in async_update_reload_and_abort

* Simplify

* Fix test

* Add sample usage

* Remove multi-line ternary
2024-10-07 09:02:58 +02:00
Erik Montnemery
48a07d531c Remove assumption in ConfigEntryItems about unique unique_id (#127399) 2024-10-03 22:27:15 +02:00
J. Nick Koston
0f29fd3e10 Switch to using fast cached_property implementation in propcache (#127339) 2024-10-03 13:11:02 -05:00
J. Nick Koston
e2b1ef053f Cache serialization of config entry storage (#127435) 2024-10-03 19:51:09 +02:00
epenet
7d3d693fe8 Align config flow reconfigure step test helper with frontend (#127329)
* Align config flow reconfigure step with frontend

* Update common.py

* Update common.py

* Adjust

* Adjust

* Fix test

* Adjust
2024-10-03 10:21:23 +02:00
epenet
21266e1c68 Add config_flow helper to get reauth/reconfigure config entry (#127115)
* Add config_flow helper to get config entry from context

* Simplify

* Apply to aussie_broadband

* Another example

* Rename and adjust docstring

* Simplify

* Add test

* Refactor to hide context

* Raise

* Improve coverage

* Use AttributeError

* Use ValueError

* Raise UnknownEntry
2024-10-02 12:00:07 +02:00
epenet
b95dfe2b00 Add test helper for starting reconfiguration flow (#127154) 2024-10-01 12:18:07 +02:00
epenet
4bb768f39c Add test for start_reauth_flow test helper (#127093)
* Improve docstring in start_reauth_flow

* Add test

* Make private

* Make fully private until actually needed
2024-09-30 14:28:13 +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
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
7ba9d1fe65 Use mock_config_flow helper in config_entries tests (#126251) 2024-09-19 13:57:27 +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
epenet
ba3872ff87 Add missing hass type in tests/*.py (#124048) 2024-08-18 15:42:41 +02:00
epenet
ad26db7dc8 Replace pylint broad-exception-raised rule with ruff (#123021) 2024-08-02 12:24:03 +02:00
Robert Resch
ad50136dbd Add created_at/modified_at to config entries (#122456) 2024-07-29 22:08:46 +02:00
epenet
075550b7ba Use HOMEASSISTANT_DOMAIN alias for core DOMAIN in tests (#122762) 2024-07-29 12:51:12 +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
epenet
c70cfbb535 Fix arguments-renamed pylint warning in tests (#119473) 2024-06-12 12:25:29 +02:00
epenet
2a7e78a80f Ignore broad-exception-raised pylint warnings in tests (#119468) 2024-06-12 12:21:41 +02:00
epenet
65befcf5d4 Fix import pylint warning in core tests (#119359) 2024-06-11 15:04:00 +02: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
279483ddb0 Import Generator from typing_extensions (2) (#118989) 2024-06-06 17:24:22 +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
epenet
0b4f1cff98 Use issue_registry fixture in core tests (#118042) 2024-05-24 15:26:32 +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
7714f807b4 Detect incorrect exception in forwarded platforms (#117754)
* Detect incorrect exception in forwarded platforms

If an integration raises ConfigEntryError/ConfigEntryAuthFailed/ConfigEntryAuthFailed
in a forwarded platform it would affect the state of the config entry and cause it to
process unloads and setup retries in while the other platforms continued to setup

* Detect incorrect exception in forwarded platforms

If an integration raises ConfigEntryError/ConfigEntryAuthFailed/ConfigEntryAuthFailed
in a forwarded platform it would affect the state of the config entry and cause it to
process unloads and setup retries in while the other platforms continued to setup

* Update homeassistant/config_entries.py

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

* adjust

* fix

---------

Co-authored-by: Paulus Schoutsen <balloob@gmail.com>
2024-05-20 20:01:59 -04:00
J. Nick Koston
13ba8e62a9 Fix race in config entry setup (#117756) 2024-05-20 09:47:47 +02:00
Marc Mueller
3434fb70fb Remove ConfigEntry runtime_data on unload (#117312) 2024-05-12 13:53:22 -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
Erik Montnemery
f55fcca0bb Tweak config_entries tests (#117242) 2024-05-11 21:45:03 +02:00
Erik Montnemery
021b057a87 Use mock_config_flow helper in config_entries tests (#117241) 2024-05-11 14:11:18 -04: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
c74c2f3652 Add state check to config entry setup to ensure it cannot be setup twice (#117193) 2024-05-11 07:09:28 +09:00
Sid
ac54cdcdb4 Enable Ruff RUF010 (#115371)
Co-authored-by: J. Nick Koston <nick@koston.org>
2024-05-08 23:54:49 +02:00