Skip to content

Commit

Permalink
Add conversation supported feature CONTROL (#121036)
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob authored Jul 3, 2024
1 parent ac57eb7 commit a885bdf
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
2 changes: 2 additions & 0 deletions homeassistant/components/conversation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
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
Expand All @@ -58,6 +59,7 @@
"ConversationEntity",
"ConversationInput",
"ConversationResult",
"ConversationEntityFeature",
]

_LOGGER = logging.getLogger(__name__)
Expand Down
8 changes: 8 additions & 0 deletions homeassistant/components/conversation/const.py
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -12,3 +14,9 @@

SERVICE_PROCESS = "process"
SERVICE_RELOAD = "reload"


class ConversationEntityFeature(IntFlag):
"""Supported features of the conversation entity."""

CONTROL = 1
3 changes: 2 additions & 1 deletion homeassistant/components/conversation/default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
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

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions homeassistant/components/conversation/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
from homeassistant.helpers.restore_state import RestoreEntity
from homeassistant.util import dt as dt_util

from .const import ConversationEntityFeature
from .models import ConversationInput, ConversationResult


class ConversationEntity(RestoreEntity):
"""Entity that supports conversations."""

_attr_should_poll = False
_attr_supported_features = ConversationEntityFeature(0)
__last_activity: str | None = None

@property
Expand Down
15 changes: 14 additions & 1 deletion tests/components/conversation/test_default_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit a885bdf

Please sign in to comment.