mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Enumerate openai.Models to validate config (#99438)
This commit is contained in:
parent
62473936e2
commit
df025b5993
@ -89,7 +89,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||||||
try:
|
try:
|
||||||
await hass.async_add_executor_job(
|
await hass.async_add_executor_job(
|
||||||
partial(
|
partial(
|
||||||
openai.Engine.list,
|
openai.Model.list,
|
||||||
api_key=entry.data[CONF_API_KEY],
|
api_key=entry.data[CONF_API_KEY],
|
||||||
request_timeout=10,
|
request_timeout=10,
|
||||||
)
|
)
|
||||||
|
@ -60,7 +60,7 @@ async def validate_input(hass: HomeAssistant, data: dict[str, Any]) -> None:
|
|||||||
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
Data has the keys from STEP_USER_DATA_SCHEMA with values provided by the user.
|
||||||
"""
|
"""
|
||||||
openai.api_key = data[CONF_API_KEY]
|
openai.api_key = data[CONF_API_KEY]
|
||||||
await hass.async_add_executor_job(partial(openai.Engine.list, request_timeout=10))
|
await hass.async_add_executor_job(partial(openai.Model.list, request_timeout=10))
|
||||||
|
|
||||||
|
|
||||||
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
class ConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
@ -25,7 +25,7 @@ def mock_config_entry(hass):
|
|||||||
async def mock_init_component(hass, mock_config_entry):
|
async def mock_init_component(hass, mock_config_entry):
|
||||||
"""Initialize integration."""
|
"""Initialize integration."""
|
||||||
with patch(
|
with patch(
|
||||||
"openai.Engine.list",
|
"openai.Model.list",
|
||||||
):
|
):
|
||||||
assert await async_setup_component(hass, "openai_conversation", {})
|
assert await async_setup_component(hass, "openai_conversation", {})
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
@ -32,7 +32,7 @@ async def test_form(hass: HomeAssistant) -> None:
|
|||||||
assert result["errors"] is None
|
assert result["errors"] is None
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.openai_conversation.config_flow.openai.Engine.list",
|
"homeassistant.components.openai_conversation.config_flow.openai.Model.list",
|
||||||
), patch(
|
), patch(
|
||||||
"homeassistant.components.openai_conversation.async_setup_entry",
|
"homeassistant.components.openai_conversation.async_setup_entry",
|
||||||
return_value=True,
|
return_value=True,
|
||||||
@ -88,7 +88,7 @@ async def test_form_invalid_auth(hass: HomeAssistant, side_effect, error) -> Non
|
|||||||
)
|
)
|
||||||
|
|
||||||
with patch(
|
with patch(
|
||||||
"homeassistant.components.openai_conversation.config_flow.openai.Engine.list",
|
"homeassistant.components.openai_conversation.config_flow.openai.Model.list",
|
||||||
side_effect=side_effect,
|
side_effect=side_effect,
|
||||||
):
|
):
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
@ -140,7 +140,7 @@ async def test_template_error(
|
|||||||
},
|
},
|
||||||
)
|
)
|
||||||
with patch(
|
with patch(
|
||||||
"openai.Engine.list",
|
"openai.Model.list",
|
||||||
), patch("openai.ChatCompletion.acreate"):
|
), patch("openai.ChatCompletion.acreate"):
|
||||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||||
await hass.async_block_till_done()
|
await hass.async_block_till_done()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user