Skip to content

Commit

Permalink
Change Assist satellite state names (#126926)
Browse files Browse the repository at this point in the history
* Change state names

* Update homeassistant/components/assist_satellite/strings.json

---------

Co-authored-by: Joost Lekkerkerker <joostlek@outlook.com>
  • Loading branch information
2 people authored and frenck committed Sep 27, 2024
1 parent ba8e9bc commit 02e15a4
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 31 deletions.
18 changes: 9 additions & 9 deletions homeassistant/components/assist_satellite/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
class AssistSatelliteState(StrEnum):
"""Valid states of an Assist satellite entity."""

LISTENING_WAKE_WORD = "listening_wake_word"
"""Device is streaming audio for wake word detection to Home Assistant."""
IDLE = "idle"
"""Device is waiting for user input, such as a wake word or a button press."""

LISTENING_COMMAND = "listening_command"
LISTENING = "listening"
"""Device is streaming audio with the voice command to Home Assistant."""

PROCESSING = "processing"
Expand Down Expand Up @@ -117,7 +117,7 @@ class AssistSatelliteEntity(entity.Entity):
_attr_tts_options: dict[str, Any] | None = None
_pipeline_task: asyncio.Task | None = None

__assist_satellite_state = AssistSatelliteState.LISTENING_WAKE_WORD
__assist_satellite_state = AssistSatelliteState.IDLE

@final
@property
Expand Down Expand Up @@ -242,7 +242,7 @@ async def async_internal_announce(
)
finally:
self._is_announcing = False
self._set_state(AssistSatelliteState.LISTENING_WAKE_WORD)
self._set_state(AssistSatelliteState.IDLE)

async def async_announce(self, announcement: AssistSatelliteAnnouncement) -> None:
"""Announce media on the satellite.
Expand Down Expand Up @@ -363,9 +363,9 @@ def on_pipeline_event(self, event: PipelineEvent) -> None:
def _internal_on_pipeline_event(self, event: PipelineEvent) -> None:
"""Set state based on pipeline stage."""
if event.type is PipelineEventType.WAKE_WORD_START:
self._set_state(AssistSatelliteState.LISTENING_WAKE_WORD)
self._set_state(AssistSatelliteState.IDLE)
elif event.type is PipelineEventType.STT_START:
self._set_state(AssistSatelliteState.LISTENING_COMMAND)
self._set_state(AssistSatelliteState.LISTENING)
elif event.type is PipelineEventType.INTENT_START:
self._set_state(AssistSatelliteState.PROCESSING)
elif event.type is PipelineEventType.INTENT_END:
Expand All @@ -379,7 +379,7 @@ def _internal_on_pipeline_event(self, event: PipelineEvent) -> None:
self._set_state(AssistSatelliteState.RESPONDING)
elif event.type is PipelineEventType.RUN_END:
if not self._run_has_tts:
self._set_state(AssistSatelliteState.LISTENING_WAKE_WORD)
self._set_state(AssistSatelliteState.IDLE)

self.on_pipeline_event(event)

Expand All @@ -392,7 +392,7 @@ def _set_state(self, state: AssistSatelliteState) -> None:
@callback
def tts_response_finished(self) -> None:
"""Tell entity that the text-to-speech response has finished playing."""
self._set_state(AssistSatelliteState.LISTENING_WAKE_WORD)
self._set_state(AssistSatelliteState.IDLE)

@callback
def _resolve_pipeline(self) -> str | None:
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/components/assist_satellite/strings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"_": {
"name": "Assist satellite",
"state": {
"listening_wake_word": "Wake word",
"listening_command": "Voice command",
"idle": "[%key:common::state::idle%]",
"listening": "Listening",
"responding": "Responding",
"processing": "Processing"
}
Expand Down
22 changes: 11 additions & 11 deletions tests/components/assist_satellite/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_entity_state(

state = hass.states.get(ENTITY_ID)
assert state is not None
assert state.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert state.state == AssistSatelliteState.IDLE

context = Context()
audio_stream = object()
Expand Down Expand Up @@ -73,18 +73,18 @@ async def test_entity_state(
assert kwargs["end_stage"] == PipelineStage.TTS

for event_type, event_data, expected_state in (
(PipelineEventType.RUN_START, {}, AssistSatelliteState.LISTENING_WAKE_WORD),
(PipelineEventType.RUN_END, {}, AssistSatelliteState.LISTENING_WAKE_WORD),
(PipelineEventType.RUN_START, {}, AssistSatelliteState.IDLE),
(PipelineEventType.RUN_END, {}, AssistSatelliteState.IDLE),
(
PipelineEventType.WAKE_WORD_START,
{},
AssistSatelliteState.LISTENING_WAKE_WORD,
AssistSatelliteState.IDLE,
),
(PipelineEventType.WAKE_WORD_END, {}, AssistSatelliteState.LISTENING_WAKE_WORD),
(PipelineEventType.STT_START, {}, AssistSatelliteState.LISTENING_COMMAND),
(PipelineEventType.STT_VAD_START, {}, AssistSatelliteState.LISTENING_COMMAND),
(PipelineEventType.STT_VAD_END, {}, AssistSatelliteState.LISTENING_COMMAND),
(PipelineEventType.STT_END, {}, AssistSatelliteState.LISTENING_COMMAND),
(PipelineEventType.WAKE_WORD_END, {}, AssistSatelliteState.IDLE),
(PipelineEventType.STT_START, {}, AssistSatelliteState.LISTENING),
(PipelineEventType.STT_VAD_START, {}, AssistSatelliteState.LISTENING),
(PipelineEventType.STT_VAD_END, {}, AssistSatelliteState.LISTENING),
(PipelineEventType.STT_END, {}, AssistSatelliteState.LISTENING),
(PipelineEventType.INTENT_START, {}, AssistSatelliteState.PROCESSING),
(
PipelineEventType.INTENT_END,
Expand All @@ -105,7 +105,7 @@ async def test_entity_state(

entity.tts_response_finished()
state = hass.states.get(ENTITY_ID)
assert state.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert state.state == AssistSatelliteState.IDLE


async def test_new_pipeline_cancels_pipeline(
Expand Down Expand Up @@ -241,7 +241,7 @@ def tts_generate_media_source_id(
target={"entity_id": "assist_satellite.test_entity"},
blocking=True,
)
assert entity.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert entity.state == AssistSatelliteState.IDLE

assert entity.announcements[0] == expected_params

Expand Down
10 changes: 5 additions & 5 deletions tests/components/esphome/test_assist_satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ async def async_pipeline_from_audio_stream(*args, device_id, **kwargs):
)

# Wake word
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE

event_callback(
PipelineEvent(
Expand Down Expand Up @@ -242,7 +242,7 @@ async def async_pipeline_from_audio_stream(*args, device_id, **kwargs):
VoiceAssistantEventType.VOICE_ASSISTANT_STT_START,
{},
)
assert satellite.state == AssistSatelliteState.LISTENING_COMMAND
assert satellite.state == AssistSatelliteState.LISTENING

event_callback(
PipelineEvent(
Expand Down Expand Up @@ -761,7 +761,7 @@ def tts_response_finished():
)
await tts_finished.wait()

assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE


async def test_timer_events(
Expand Down Expand Up @@ -1214,7 +1214,7 @@ async def send_voice_assistant_announcement_await_response(
blocking=True,
)
await done.wait()
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE


async def test_announce_media_id(
Expand Down Expand Up @@ -1297,7 +1297,7 @@ async def send_voice_assistant_announcement_await_response(
blocking=True,
)
await done.wait()
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE

mock_async_create_proxy_url.assert_called_once_with(
hass,
Expand Down
8 changes: 4 additions & 4 deletions tests/components/voip/test_voip.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ async def test_pipeline(
assert voip_user_id

# Satellite is muted until a call begins
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE

done = asyncio.Event()

Expand Down Expand Up @@ -251,7 +251,7 @@ async def async_pipeline_from_audio_stream(
)
)

assert satellite.state == AssistSatelliteState.LISTENING_COMMAND
assert satellite.state == AssistSatelliteState.LISTENING

# Fake STT result
event_callback(
Expand Down Expand Up @@ -345,7 +345,7 @@ async def async_get_media_source_audio(
satellite.transport = Mock()

satellite.connection_made(satellite.transport)
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE

# Ensure audio queue is cleared before pipeline starts
satellite._audio_queue.put_nowait(bad_chunk)
Expand All @@ -370,7 +370,7 @@ def send_audio(*args, **kwargs):
await done.wait()

# Finished speaking
assert satellite.state == AssistSatelliteState.LISTENING_WAKE_WORD
assert satellite.state == AssistSatelliteState.IDLE


async def test_stt_stream_timeout(
Expand Down

0 comments on commit 02e15a4

Please sign in to comment.