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>pull/117367/head
parent
9e146a51c2
commit
471e2a17a2
|
@ -1812,9 +1812,9 @@ class ConfigEntries:
|
|||
|
||||
if entry.state is not ConfigEntryState.NOT_LOADED:
|
||||
raise OperationNotAllowed(
|
||||
f"The config entry {entry.title} ({entry.domain}) with entry_id"
|
||||
f" {entry.entry_id} cannot be set up because it is already loaded"
|
||||
f" in the {entry.state} state"
|
||||
f"The config entry '{entry.title}' ({entry.domain}) with entry_id"
|
||||
f" '{entry.entry_id}' cannot be set up because it is in state "
|
||||
f"{entry.state}, but needs to be in the {ConfigEntryState.NOT_LOADED} state"
|
||||
)
|
||||
|
||||
# Setup Component if not set up yet
|
||||
|
@ -1844,9 +1844,9 @@ class ConfigEntries:
|
|||
|
||||
if not entry.state.recoverable:
|
||||
raise OperationNotAllowed(
|
||||
f"The config entry {entry.title} ({entry.domain}) with entry_id"
|
||||
f" {entry.entry_id} cannot be unloaded because it is not in a"
|
||||
f" recoverable state ({entry.state})"
|
||||
f"The config entry '{entry.title}' ({entry.domain}) with entry_id"
|
||||
f" '{entry.entry_id}' cannot be unloaded because it is in the non"
|
||||
f" recoverable state {entry.state}"
|
||||
)
|
||||
|
||||
if _lock:
|
||||
|
@ -2049,9 +2049,10 @@ class ConfigEntries:
|
|||
async with entry.setup_lock:
|
||||
if entry.state is not ConfigEntryState.LOADED:
|
||||
raise OperationNotAllowed(
|
||||
f"The config entry {entry.title} ({entry.domain}) with entry_id"
|
||||
f" {entry.entry_id} cannot forward setup for {platforms} because it"
|
||||
f" is not loaded in the {entry.state} state"
|
||||
f"The config entry '{entry.title}' ({entry.domain}) with "
|
||||
f"entry_id '{entry.entry_id}' cannot forward setup for "
|
||||
f"{platforms} because it is in state {entry.state}, but needs "
|
||||
f"to be in the {ConfigEntryState.LOADED} state"
|
||||
)
|
||||
await self._async_forward_entry_setups_locked(entry, platforms)
|
||||
else:
|
||||
|
@ -2108,9 +2109,10 @@ class ConfigEntries:
|
|||
async with entry.setup_lock:
|
||||
if entry.state is not ConfigEntryState.LOADED:
|
||||
raise OperationNotAllowed(
|
||||
f"The config entry {entry.title} ({entry.domain}) with entry_id"
|
||||
f" {entry.entry_id} cannot forward setup for {domain} because it"
|
||||
f" is not loaded in the {entry.state} state"
|
||||
f"The config entry '{entry.title}' ({entry.domain}) with "
|
||||
f"entry_id '{entry.entry_id}' cannot forward setup for "
|
||||
f"{domain} because it is in state {entry.state}, but needs "
|
||||
f"to be in the {ConfigEntryState.LOADED} state"
|
||||
)
|
||||
return await self._async_forward_entry_setup(entry, domain, True)
|
||||
result = await self._async_forward_entry_setup(entry, domain, True)
|
||||
|
|
|
@ -5606,9 +5606,10 @@ async def test_config_entry_unloaded_during_platform_setups(
|
|||
del task
|
||||
|
||||
assert (
|
||||
"OperationNotAllowed: The config entry Mock Title (test) with "
|
||||
"entry_id test2 cannot forward setup for ['light'] because it is "
|
||||
"not loaded in the ConfigEntryState.NOT_LOADED state"
|
||||
"OperationNotAllowed: The config entry 'Mock Title' (test) with "
|
||||
"entry_id 'test2' cannot forward setup for ['light'] because it is "
|
||||
"in state ConfigEntryState.NOT_LOADED, but needs to be in the "
|
||||
"ConfigEntryState.LOADED state"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
|
@ -5824,9 +5825,10 @@ async def test_config_entry_unloaded_during_platform_setup(
|
|||
del task
|
||||
|
||||
assert (
|
||||
"OperationNotAllowed: The config entry Mock Title (test) with "
|
||||
"entry_id test2 cannot forward setup for light because it is "
|
||||
"not loaded in the ConfigEntryState.NOT_LOADED state"
|
||||
"OperationNotAllowed: The config entry 'Mock Title' (test) with "
|
||||
"entry_id 'test2' cannot forward setup for light because it is "
|
||||
"in state ConfigEntryState.NOT_LOADED, but needs to be in the "
|
||||
"ConfigEntryState.LOADED state"
|
||||
) in caplog.text
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue