Prevent config entries from being reloaded while they are setting up (#73387)

This commit is contained in:
J. Nick Koston 2022-06-12 20:05:08 -10:00 committed by GitHub
parent 1187009280
commit 7a422774b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -90,7 +90,7 @@ class ConfigEntryState(Enum):
"""The config entry has not been loaded"""
FAILED_UNLOAD = "failed_unload", False
"""An error occurred when trying to unload the entry"""
SETUP_IN_PROGRESS = "setup_in_progress", True
SETUP_IN_PROGRESS = "setup_in_progress", False
"""The config entry is setting up."""
_recoverable: bool
@ -104,7 +104,11 @@ class ConfigEntryState(Enum):
@property
def recoverable(self) -> bool:
"""Get if the state is recoverable."""
"""Get if the state is recoverable.
If the entry is state is recoverable, unloads
and reloads are allowed.
"""
return self._recoverable

View File

@ -3260,3 +3260,15 @@ async def test_unique_id_update_while_setup_in_progress(
assert len(async_reload.mock_calls) == 0
await hass.async_block_till_done()
assert entry.state is config_entries.ConfigEntryState.LOADED
async def test_disallow_entry_reload_with_setup_in_progresss(hass, manager):
"""Test we do not allow reload while the config entry is still setting up."""
entry = MockConfigEntry(
domain="comp", state=config_entries.ConfigEntryState.SETUP_IN_PROGRESS
)
entry.add_to_hass(hass)
with pytest.raises(config_entries.OperationNotAllowed):
assert await manager.async_reload(entry.entry_id)
assert entry.state is config_entries.ConfigEntryState.SETUP_IN_PROGRESS