Add conversation supported feature CONTROL (#121036)

This commit is contained in:
Paulus Schoutsen 2024-07-03 14:30:51 +02:00 committed by GitHub
parent ac57eb7614
commit a885bdfe76
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 28 additions and 2 deletions

View File

@ -40,6 +40,7 @@ from .const import (
OLD_HOME_ASSISTANT_AGENT,
SERVICE_PROCESS,
SERVICE_RELOAD,
ConversationEntityFeature,
)
from .default_agent import async_get_default_agent, async_setup_default_agent
from .entity import ConversationEntity
@ -58,6 +59,7 @@ __all__ = [
"ConversationEntity",
"ConversationInput",
"ConversationResult",
"ConversationEntityFeature",
]
_LOGGER = logging.getLogger(__name__)

View File

@ -1,5 +1,7 @@
"""Const for conversation integration."""
from enum import IntFlag
DOMAIN = "conversation"
DEFAULT_EXPOSED_ATTRIBUTES = {"device_class"}
HOME_ASSISTANT_AGENT = "conversation.home_assistant"
@ -12,3 +14,9 @@ ATTR_CONVERSATION_ID = "conversation_id"
SERVICE_PROCESS = "process"
SERVICE_RELOAD = "reload"
class ConversationEntityFeature(IntFlag):
"""Supported features of the conversation entity."""
CONTROL = 1

View File

@ -44,7 +44,7 @@ from homeassistant.helpers.entity_component import EntityComponent
from homeassistant.helpers.event import async_track_state_added_domain
from homeassistant.util.json import JsonObjectType, json_loads_object
from .const import DEFAULT_EXPOSED_ATTRIBUTES, DOMAIN
from .const import DEFAULT_EXPOSED_ATTRIBUTES, DOMAIN, ConversationEntityFeature
from .entity import ConversationEntity
from .models import ConversationInput, ConversationResult
@ -147,6 +147,7 @@ class DefaultAgent(ConversationEntity):
"""Default agent for conversation agent."""
_attr_name = "Home Assistant"
_attr_supported_features = ConversationEntityFeature.CONTROL
def __init__(
self, hass: core.HomeAssistant, config_intents: dict[str, Any]

View File

@ -7,6 +7,7 @@ from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import dt as dt_util
from .const import ConversationEntityFeature
from .models import ConversationInput, ConversationResult
@ -14,6 +15,7 @@ class ConversationEntity(RestoreEntity):
"""Entity that supports conversations."""
_attr_should_poll = False
_attr_supported_features = ConversationEntityFeature(0)
__last_activity: str | None = None
@property

View File

@ -17,7 +17,12 @@ from homeassistant.components.intent import (
TimerInfo,
async_register_timer_handler,
)
from homeassistant.const import ATTR_DEVICE_CLASS, ATTR_FRIENDLY_NAME, STATE_CLOSED
from homeassistant.const import (
ATTR_DEVICE_CLASS,
ATTR_FRIENDLY_NAME,
STATE_CLOSED,
STATE_UNKNOWN,
)
from homeassistant.core import DOMAIN as HASS_DOMAIN, Context, HomeAssistant, callback
from homeassistant.helpers import (
area_registry as ar,
@ -173,6 +178,14 @@ async def test_conversation_agent(hass: HomeAssistant) -> None:
):
assert agent.supported_languages == ["dwarvish", "elvish", "entish"]
state = hass.states.get(agent.entity_id)
assert state
assert state.state == STATE_UNKNOWN
assert (
state.attributes["supported_features"]
== conversation.ConversationEntityFeature.CONTROL
)
async def test_expose_flag_automatically_set(
hass: HomeAssistant,