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