OpenAI make supported features reflect the config entry options (#123047)

This commit is contained in:
Paulus Schoutsen 2024-08-02 12:08:44 +02:00 committed by Franck Nijhof
parent bb597a908d
commit abeba39842
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 17 additions and 0 deletions

View file

@ -23,6 +23,7 @@ from voluptuous_openapi import convert
from homeassistant.components import assist_pipeline, conversation
from homeassistant.components.conversation import trace
from homeassistant.config_entries import ConfigEntry
from homeassistant.const import CONF_LLM_HASS_API, MATCH_ALL
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import HomeAssistantError, TemplateError
@ -109,6 +110,9 @@ class OpenAIConversationEntity(
self.hass, "conversation", self.entry.entry_id, self.entity_id
)
conversation.async_set_agent(self.hass, self.entry, self)
self.entry.async_on_unload(
self.entry.add_update_listener(self._async_entry_update_listener)
)
async def async_will_remove_from_hass(self) -> None:
"""When entity will be removed from Home Assistant."""
@ -319,3 +323,14 @@ class OpenAIConversationEntity(
return conversation.ConversationResult(
response=intent_response, conversation_id=conversation_id
)
async def _async_entry_update_listener(
self, hass: HomeAssistant, entry: ConfigEntry
) -> None:
"""Handle options update."""
if entry.options.get(CONF_LLM_HASS_API):
self._attr_supported_features = (
conversation.ConversationEntityFeature.CONTROL
)
else:
self._attr_supported_features = conversation.ConversationEntityFeature(0)

View file

@ -521,6 +521,8 @@ async def test_unknown_hass_api(
},
)
await hass.async_block_till_done()
result = await conversation.async_converse(
hass, "hello", None, Context(), agent_id=mock_config_entry.entry_id
)