OpenAI make supported features reflect the config entry options (#123047)
This commit is contained in:
parent
449afe9e6f
commit
adf8515698
2 changed files with 17 additions and 0 deletions
|
@ -23,6 +23,7 @@ from voluptuous_openapi import convert
|
||||||
|
|
||||||
from homeassistant.components import assist_pipeline, conversation
|
from homeassistant.components import assist_pipeline, conversation
|
||||||
from homeassistant.components.conversation import trace
|
from homeassistant.components.conversation import trace
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import CONF_LLM_HASS_API, MATCH_ALL
|
from homeassistant.const import CONF_LLM_HASS_API, MATCH_ALL
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.exceptions import HomeAssistantError, TemplateError
|
from homeassistant.exceptions import HomeAssistantError, TemplateError
|
||||||
|
@ -109,6 +110,9 @@ class OpenAIConversationEntity(
|
||||||
self.hass, "conversation", self.entry.entry_id, self.entity_id
|
self.hass, "conversation", self.entry.entry_id, self.entity_id
|
||||||
)
|
)
|
||||||
conversation.async_set_agent(self.hass, self.entry, self)
|
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:
|
async def async_will_remove_from_hass(self) -> None:
|
||||||
"""When entity will be removed from Home Assistant."""
|
"""When entity will be removed from Home Assistant."""
|
||||||
|
@ -319,3 +323,14 @@ class OpenAIConversationEntity(
|
||||||
return conversation.ConversationResult(
|
return conversation.ConversationResult(
|
||||||
response=intent_response, conversation_id=conversation_id
|
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)
|
||||||
|
|
|
@ -521,6 +521,8 @@ async def test_unknown_hass_api(
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
result = await conversation.async_converse(
|
result = await conversation.async_converse(
|
||||||
hass, "hello", None, Context(), agent_id=mock_config_entry.entry_id
|
hass, "hello", None, Context(), agent_id=mock_config_entry.entry_id
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Reference in a new issue