Skip to content

Commit

Permalink
Set responding state in assist satellite announcements (home-assistan…
Browse files Browse the repository at this point in the history
…t#125632)

Set responding state in announcements
  • Loading branch information
synesthesiam authored Sep 10, 2024
1 parent 06e8334 commit bd5892f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions homeassistant/components/assist_satellite/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,14 @@ async def async_internal_announce(
raise SatelliteBusyError

self._is_announcing = True
self._set_state(AssistSatelliteState.RESPONDING)

try:
# Block until announcement is finished
await self.async_announce(message, media_id)
finally:
self._is_announcing = False
self.tts_response_finished()

async def async_announce(self, message: str, media_id: str) -> None:
"""Announce media on the satellite.
Expand Down
27 changes: 26 additions & 1 deletion tests/components/assist_satellite/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,33 @@ async def test_announce(
tts_voice="test-voice",
)

entity._attr_tts_options = {"test-option": "test-value"}

original_announce = entity.async_announce
announce_started = asyncio.Event()

async def async_announce(message, media_id):
# Verify state change
assert entity.state == AssistSatelliteState.RESPONDING
await original_announce(message, media_id)
announce_started.set()

def tts_generate_media_source_id(
hass: HomeAssistant,
message: str,
engine: str | None = None,
language: str | None = None,
options: dict | None = None,
cache: bool | None = None,
):
# Check that TTS options are passed here
assert options == {"test-option": "test-value", "voice": "test-voice"}
return "media-source://bla"

with (
patch(
"homeassistant.components.assist_satellite.entity.tts_generate_media_source_id",
return_value="media-source://bla",
new=tts_generate_media_source_id,
),
patch(
"homeassistant.components.media_source.async_resolve_media",
Expand All @@ -141,6 +164,7 @@ async def test_announce(
mime_type="audio/mp3",
),
),
patch.object(entity, "async_announce", new=async_announce),
):
await hass.services.async_call(
"assist_satellite",
Expand All @@ -149,6 +173,7 @@ async def test_announce(
target={"entity_id": "assist_satellite.test_entity"},
blocking=True,
)
assert entity.state == AssistSatelliteState.LISTENING_WAKE_WORD

assert entity.announcements[0] == expected_params

Expand Down

0 comments on commit bd5892f

Please sign in to comment.