forked from home-assistant/core
Do not allow addin subentry when not loaded
This commit is contained in:
@@ -14,6 +14,7 @@ import voluptuous as vol
|
|||||||
from homeassistant.config_entries import (
|
from homeassistant.config_entries import (
|
||||||
SOURCE_REAUTH,
|
SOURCE_REAUTH,
|
||||||
ConfigEntry,
|
ConfigEntry,
|
||||||
|
ConfigEntryState,
|
||||||
ConfigFlow,
|
ConfigFlow,
|
||||||
ConfigFlowResult,
|
ConfigFlowResult,
|
||||||
ConfigSubentryFlow,
|
ConfigSubentryFlow,
|
||||||
@@ -192,6 +193,10 @@ class ConversationSubentryFlowHandler(ConfigSubentryFlow):
|
|||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> SubentryFlowResult:
|
) -> SubentryFlowResult:
|
||||||
"""Set conversation options."""
|
"""Set conversation options."""
|
||||||
|
# abort if entry is not loaded
|
||||||
|
if self._get_entry().state != ConfigEntryState.LOADED:
|
||||||
|
return self.async_abort(reason="entry_not_loaded")
|
||||||
|
|
||||||
errors: dict[str, str] = {}
|
errors: dict[str, str] = {}
|
||||||
|
|
||||||
if user_input is None:
|
if user_input is None:
|
||||||
|
@@ -54,6 +54,7 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"abort": {
|
"abort": {
|
||||||
|
"entry_not_loaded": "Cannot add things while the configuration is disabled.",
|
||||||
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
"reconfigure_successful": "[%key:common::config_flow::abort::reconfigure_successful%]"
|
||||||
},
|
},
|
||||||
"error": {
|
"error": {
|
||||||
|
@@ -129,8 +129,6 @@ async def test_creating_conversation_subentry(
|
|||||||
mock_config_entry: MockConfigEntry,
|
mock_config_entry: MockConfigEntry,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test creating a conversation subentry."""
|
"""Test creating a conversation subentry."""
|
||||||
mock_config_entry.add_to_hass(hass)
|
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"google.genai.models.AsyncModels.list",
|
"google.genai.models.AsyncModels.list",
|
||||||
return_value=get_models_pager(),
|
return_value=get_models_pager(),
|
||||||
@@ -163,6 +161,26 @@ async def test_creating_conversation_subentry(
|
|||||||
assert result2["data"] == processed_options
|
assert result2["data"] == processed_options
|
||||||
|
|
||||||
|
|
||||||
|
async def test_creating_conversation_subentry_not_loaded(
|
||||||
|
hass: HomeAssistant,
|
||||||
|
mock_init_component: None,
|
||||||
|
mock_config_entry: MockConfigEntry,
|
||||||
|
) -> None:
|
||||||
|
"""Test creating a conversation subentry."""
|
||||||
|
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||||
|
with patch(
|
||||||
|
"google.genai.models.AsyncModels.list",
|
||||||
|
return_value=get_models_pager(),
|
||||||
|
):
|
||||||
|
result = await hass.config_entries.subentries.async_init(
|
||||||
|
(mock_config_entry.entry_id, "conversation"),
|
||||||
|
context={"source": config_entries.SOURCE_USER},
|
||||||
|
)
|
||||||
|
|
||||||
|
assert result["type"] is FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "entry_not_loaded"
|
||||||
|
|
||||||
|
|
||||||
def will_options_be_rendered_again(current_options, new_options) -> bool:
|
def will_options_be_rendered_again(current_options, new_options) -> bool:
|
||||||
"""Determine if options will be rendered again."""
|
"""Determine if options will be rendered again."""
|
||||||
return current_options.get(CONF_RECOMMENDED) != new_options.get(CONF_RECOMMENDED)
|
return current_options.get(CONF_RECOMMENDED) != new_options.get(CONF_RECOMMENDED)
|
||||||
|
Reference in New Issue
Block a user