Add preannounce boolean for announce/start conversation (#141930)

* Add preannounce boolean

* Fix disabling preannounce in wizard

* Fix casing

* Fix type of preannounce_media_id

* Adjust description of preannounce_media_id
This commit is contained in:
Michael Hansen 2025-03-31 13:29:07 -05:00 committed by GitHub
parent ef989160af
commit 28dbf6e3dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 50 additions and 24 deletions

View File

@ -60,7 +60,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
{
vol.Optional("message"): str,
vol.Optional("media_id"): str,
vol.Optional("preannounce_media_id"): vol.Any(str, None),
vol.Optional("preannounce"): bool,
vol.Optional("preannounce_media_id"): str,
}
),
cv.has_at_least_one_key("message", "media_id"),
@ -75,7 +76,8 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
{
vol.Optional("start_message"): str,
vol.Optional("start_media_id"): str,
vol.Optional("preannounce_media_id"): vol.Any(str, None),
vol.Optional("preannounce"): bool,
vol.Optional("preannounce_media_id"): str,
vol.Optional("extra_system_prompt"): str,
}
),

View File

@ -180,7 +180,8 @@ class AssistSatelliteEntity(entity.Entity):
self,
message: str | None = None,
media_id: str | None = None,
preannounce_media_id: str | None = PREANNOUNCE_URL,
preannounce: bool = True,
preannounce_media_id: str = PREANNOUNCE_URL,
) -> None:
"""Play and show an announcement on the satellite.
@ -190,8 +191,8 @@ class AssistSatelliteEntity(entity.Entity):
If media_id is provided, it is played directly. It is possible
to omit the message and the satellite will not show any text.
If preannounce is True, a sound is played before the announcement.
If preannounce_media_id is provided, it overrides the default sound.
If preannounce_media_id is None, no sound is played.
Calls async_announce with message and media id.
"""
@ -201,7 +202,9 @@ class AssistSatelliteEntity(entity.Entity):
message = ""
announcement = await self._resolve_announcement_media_id(
message, media_id, preannounce_media_id
message,
media_id,
preannounce_media_id=preannounce_media_id if preannounce else None,
)
if self._is_announcing:
@ -229,7 +232,8 @@ class AssistSatelliteEntity(entity.Entity):
start_message: str | None = None,
start_media_id: str | None = None,
extra_system_prompt: str | None = None,
preannounce_media_id: str | None = PREANNOUNCE_URL,
preannounce: bool = True,
preannounce_media_id: str = PREANNOUNCE_URL,
) -> None:
"""Start a conversation from the satellite.
@ -239,8 +243,8 @@ class AssistSatelliteEntity(entity.Entity):
If start_media_id is provided, it is played directly. It is possible
to omit the message and the satellite will not show any text.
If preannounce_media_id is provided, it is played before the announcement.
If preannounce_media_id is None, no sound is played.
If preannounce is True, a sound is played before the start message or media.
If preannounce_media_id is provided, it overrides the default sound.
Calls async_start_conversation.
"""
@ -257,7 +261,9 @@ class AssistSatelliteEntity(entity.Entity):
start_message = ""
announcement = await self._resolve_announcement_media_id(
start_message, start_media_id, preannounce_media_id
start_message,
start_media_id,
preannounce_media_id=preannounce_media_id if preannounce else None,
)
if self._is_announcing:

View File

@ -15,6 +15,11 @@ announce:
required: false
selector:
text:
preannounce:
required: false
default: true
selector:
boolean:
preannounce_media_id:
required: false
selector:
@ -40,6 +45,11 @@ start_conversation:
required: false
selector:
text:
preannounce:
required: false
default: true
selector:
boolean:
preannounce_media_id:
required: false
selector:

View File

@ -24,9 +24,13 @@
"name": "Media ID",
"description": "The media ID to announce instead of using text-to-speech."
},
"preannounce": {
"name": "Preannounce",
"description": "Play a sound before the announcement."
},
"preannounce_media_id": {
"name": "Preannounce Media ID",
"description": "The media ID to play before the announcement."
"name": "Preannounce media ID",
"description": "Custom media ID to play before the announcement."
}
}
},
@ -46,9 +50,13 @@
"name": "Extra system prompt",
"description": "Provide background information to the AI about the request."
},
"preannounce": {
"name": "Preannounce",
"description": "Play a sound before the start message or media."
},
"preannounce_media_id": {
"name": "Preannounce Media ID",
"description": "The media ID to play before the start message or media."
"name": "Preannounce media ID",
"description": "Custom media ID to play before the start message or media."
}
}
}

View File

@ -199,7 +199,7 @@ async def websocket_test_connection(
hass.async_create_background_task(
satellite.async_internal_announce(
media_id=f"{CONNECTION_TEST_URL_BASE}/{connection_id}",
preannounce_media_id=None,
preannounce=False,
),
f"assist_satellite_connection_test_{msg['entity_id']}",
)

View File

@ -186,7 +186,7 @@ async def test_new_pipeline_cancels_pipeline(
("service_data", "expected_params"),
[
(
{"message": "Hello", "preannounce_media_id": None},
{"message": "Hello", "preannounce": False},
AssistSatelliteAnnouncement(
message="Hello",
media_id="http://10.10.10.10:8123/api/tts_proxy/test-token",
@ -199,7 +199,7 @@ async def test_new_pipeline_cancels_pipeline(
{
"message": "Hello",
"media_id": "media-source://given",
"preannounce_media_id": None,
"preannounce": False,
},
AssistSatelliteAnnouncement(
message="Hello",
@ -210,7 +210,7 @@ async def test_new_pipeline_cancels_pipeline(
),
),
(
{"media_id": "http://example.com/bla.mp3", "preannounce_media_id": None},
{"media_id": "http://example.com/bla.mp3", "preannounce": False},
AssistSatelliteAnnouncement(
message="",
media_id="http://example.com/bla.mp3",
@ -541,7 +541,7 @@ async def test_vad_sensitivity_entity_not_found(
{
"start_message": "Hello",
"extra_system_prompt": "Better system prompt",
"preannounce_media_id": None,
"preannounce": False,
},
(
"mock-conversation-id",
@ -559,7 +559,7 @@ async def test_vad_sensitivity_entity_not_found(
{
"start_message": "Hello",
"start_media_id": "media-source://given",
"preannounce_media_id": None,
"preannounce": False,
},
(
"mock-conversation-id",
@ -576,7 +576,7 @@ async def test_vad_sensitivity_entity_not_found(
(
{
"start_media_id": "http://example.com/given.mp3",
"preannounce_media_id": None,
"preannounce": False,
},
(
"mock-conversation-id",

View File

@ -1221,7 +1221,7 @@ async def test_announce_message(
{
"entity_id": satellite.entity_id,
"message": "test-text",
"preannounce_media_id": None,
"preannounce": False,
},
blocking=True,
)
@ -1311,7 +1311,7 @@ async def test_announce_media_id(
{
"entity_id": satellite.entity_id,
"media_id": "https://www.home-assistant.io/resolved.mp3",
"preannounce_media_id": None,
"preannounce": False,
},
blocking=True,
)
@ -1522,7 +1522,7 @@ async def test_start_conversation_message(
{
"entity_id": satellite.entity_id,
"start_message": "test-text",
"preannounce_media_id": None,
"preannounce": False,
},
blocking=True,
)
@ -1631,7 +1631,7 @@ async def test_start_conversation_media_id(
{
"entity_id": satellite.entity_id,
"start_media_id": "https://www.home-assistant.io/resolved.mp3",
"preannounce_media_id": None,
"preannounce": False,
},
blocking=True,
)