mirror of
https://github.com/home-assistant/core.git
synced 2025-07-07 21:37:07 +00:00
Add conversation supported feature CONTROL (#121036)
This commit is contained in:
parent
ac57eb7614
commit
a885bdfe76
@ -40,6 +40,7 @@ from .const import (
|
|||||||
OLD_HOME_ASSISTANT_AGENT,
|
OLD_HOME_ASSISTANT_AGENT,
|
||||||
SERVICE_PROCESS,
|
SERVICE_PROCESS,
|
||||||
SERVICE_RELOAD,
|
SERVICE_RELOAD,
|
||||||
|
ConversationEntityFeature,
|
||||||
)
|
)
|
||||||
from .default_agent import async_get_default_agent, async_setup_default_agent
|
from .default_agent import async_get_default_agent, async_setup_default_agent
|
||||||
from .entity import ConversationEntity
|
from .entity import ConversationEntity
|
||||||
@ -58,6 +59,7 @@ __all__ = [
|
|||||||
"ConversationEntity",
|
"ConversationEntity",
|
||||||
"ConversationInput",
|
"ConversationInput",
|
||||||
"ConversationResult",
|
"ConversationResult",
|
||||||
|
"ConversationEntityFeature",
|
||||||
]
|
]
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
"""Const for conversation integration."""
|
"""Const for conversation integration."""
|
||||||
|
|
||||||
|
from enum import IntFlag
|
||||||
|
|
||||||
DOMAIN = "conversation"
|
DOMAIN = "conversation"
|
||||||
DEFAULT_EXPOSED_ATTRIBUTES = {"device_class"}
|
DEFAULT_EXPOSED_ATTRIBUTES = {"device_class"}
|
||||||
HOME_ASSISTANT_AGENT = "conversation.home_assistant"
|
HOME_ASSISTANT_AGENT = "conversation.home_assistant"
|
||||||
@ -12,3 +14,9 @@ ATTR_CONVERSATION_ID = "conversation_id"
|
|||||||
|
|
||||||
SERVICE_PROCESS = "process"
|
SERVICE_PROCESS = "process"
|
||||||
SERVICE_RELOAD = "reload"
|
SERVICE_RELOAD = "reload"
|
||||||
|
|
||||||
|
|
||||||
|
class ConversationEntityFeature(IntFlag):
|
||||||
|
"""Supported features of the conversation entity."""
|
||||||
|
|
||||||
|
CONTROL = 1
|
||||||
|
@ -44,7 +44,7 @@ from homeassistant.helpers.entity_component import EntityComponent
|
|||||||
from homeassistant.helpers.event import async_track_state_added_domain
|
from homeassistant.helpers.event import async_track_state_added_domain
|
||||||
from homeassistant.util.json import JsonObjectType, json_loads_object
|
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 .entity import ConversationEntity
|
||||||
from .models import ConversationInput, ConversationResult
|
from .models import ConversationInput, ConversationResult
|
||||||
|
|
||||||
@ -147,6 +147,7 @@ class DefaultAgent(ConversationEntity):
|
|||||||
"""Default agent for conversation agent."""
|
"""Default agent for conversation agent."""
|
||||||
|
|
||||||
_attr_name = "Home Assistant"
|
_attr_name = "Home Assistant"
|
||||||
|
_attr_supported_features = ConversationEntityFeature.CONTROL
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, hass: core.HomeAssistant, config_intents: dict[str, Any]
|
self, hass: core.HomeAssistant, config_intents: dict[str, Any]
|
||||||
|
@ -7,6 +7,7 @@ from homeassistant.const import STATE_UNAVAILABLE, STATE_UNKNOWN
|
|||||||
from homeassistant.helpers.restore_state import RestoreEntity
|
from homeassistant.helpers.restore_state import RestoreEntity
|
||||||
from homeassistant.util import dt as dt_util
|
from homeassistant.util import dt as dt_util
|
||||||
|
|
||||||
|
from .const import ConversationEntityFeature
|
||||||
from .models import ConversationInput, ConversationResult
|
from .models import ConversationInput, ConversationResult
|
||||||
|
|
||||||
|
|
||||||
@ -14,6 +15,7 @@ class ConversationEntity(RestoreEntity):
|
|||||||
"""Entity that supports conversations."""
|
"""Entity that supports conversations."""
|
||||||
|
|
||||||
_attr_should_poll = False
|
_attr_should_poll = False
|
||||||
|
_attr_supported_features = ConversationEntityFeature(0)
|
||||||
__last_activity: str | None = None
|
__last_activity: str | None = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -17,7 +17,12 @@ from homeassistant.components.intent import (
|
|||||||
TimerInfo,
|
TimerInfo,
|
||||||
async_register_timer_handler,
|
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.core import DOMAIN as HASS_DOMAIN, Context, HomeAssistant, callback
|
||||||
from homeassistant.helpers import (
|
from homeassistant.helpers import (
|
||||||
area_registry as ar,
|
area_registry as ar,
|
||||||
@ -173,6 +178,14 @@ async def test_conversation_agent(hass: HomeAssistant) -> None:
|
|||||||
):
|
):
|
||||||
assert agent.supported_languages == ["dwarvish", "elvish", "entish"]
|
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(
|
async def test_expose_flag_automatically_set(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user