diff --git a/homeassistant/components/openai_conversation/config_flow.py b/homeassistant/components/openai_conversation/config_flow.py index 05ed4fe18f5f..ff1f1820c9e2 100644 --- a/homeassistant/components/openai_conversation/config_flow.py +++ b/homeassistant/components/openai_conversation/config_flow.py @@ -309,7 +309,7 @@ class OpenAISubentryFlowHandler(ConfigSubentryFlow): ] = bool if user_input is not None: - if not user_input.get(CONF_LLM_HASS_API): + if user_input.get(CONF_LLM_HASS_API) is None: user_input.pop(CONF_LLM_HASS_API, None) if user_input[CONF_RECOMMENDED]: diff --git a/tests/components/openai_conversation/test_config_flow.py b/tests/components/openai_conversation/test_config_flow.py index d83c1f263d1e..132befddc8d9 100644 --- a/tests/components/openai_conversation/test_config_flow.py +++ b/tests/components/openai_conversation/test_config_flow.py @@ -647,6 +647,25 @@ async def test_form_invalid_auth(hass: HomeAssistant, side_effect, error) -> Non @pytest.mark.parametrize( ("current_options", "new_options", "expected_options"), [ + ( # Test clearing every llm api is stored as an empty list + { + CONF_RECOMMENDED: True, + CONF_LLM_HASS_API: ["assist"], + CONF_PROMPT: "", + }, + ( + { + CONF_RECOMMENDED: True, + CONF_LLM_HASS_API: [], + CONF_PROMPT: "", + }, + ), + { + CONF_RECOMMENDED: True, + CONF_LLM_HASS_API: [], + CONF_PROMPT: "", + }, + ), ( # Test converting single llm api format to list { CONF_RECOMMENDED: True,