Skip to content

Commit 1b99ffe

Browse files
authored
Pass satellite id through assist pipeline (home-assistant#151992)
1 parent d5132e8 commit 1b99ffe

File tree

17 files changed

+90
-8
lines changed

17 files changed

+90
-8
lines changed

homeassistant/components/assist_pipeline/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ async def async_pipeline_from_audio_stream(
103103
wake_word_settings: WakeWordSettings | None = None,
104104
audio_settings: AudioSettings | None = None,
105105
device_id: str | None = None,
106+
satellite_id: str | None = None,
106107
start_stage: PipelineStage = PipelineStage.STT,
107108
end_stage: PipelineStage = PipelineStage.TTS,
108109
conversation_extra_system_prompt: str | None = None,
@@ -115,6 +116,7 @@ async def async_pipeline_from_audio_stream(
115116
pipeline_input = PipelineInput(
116117
session=session,
117118
device_id=device_id,
119+
satellite_id=satellite_id,
118120
stt_metadata=stt_metadata,
119121
stt_stream=stt_stream,
120122
wake_word_phrase=wake_word_phrase,

homeassistant/components/assist_pipeline/pipeline.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,9 @@ class PipelineRun:
583583
_device_id: str | None = None
584584
"""Optional device id set during run start."""
585585

586+
_satellite_id: str | None = None
587+
"""Optional satellite id set during run start."""
588+
586589
_conversation_data: PipelineConversationData | None = None
587590
"""Data tied to the conversation ID."""
588591

@@ -636,16 +639,21 @@ def process_event(self, event: PipelineEvent) -> None:
636639
return
637640
pipeline_data.pipeline_debug[self.pipeline.id][self.id].events.append(event)
638641

639-
def start(self, conversation_id: str, device_id: str | None) -> None:
642+
def start(
643+
self, conversation_id: str, device_id: str | None, satellite_id: str | None
644+
) -> None:
640645
"""Emit run start event."""
641646
self._device_id = device_id
647+
self._satellite_id = satellite_id
642648
self._start_debug_recording_thread()
643649

644650
data: dict[str, Any] = {
645651
"pipeline": self.pipeline.id,
646652
"language": self.language,
647653
"conversation_id": conversation_id,
648654
}
655+
if satellite_id is not None:
656+
data["satellite_id"] = satellite_id
649657
if self.runner_data is not None:
650658
data["runner_data"] = self.runner_data
651659
if self.tts_stream:
@@ -1057,7 +1065,6 @@ async def recognize_intent(
10571065
self,
10581066
intent_input: str,
10591067
conversation_id: str,
1060-
device_id: str | None,
10611068
conversation_extra_system_prompt: str | None,
10621069
) -> str:
10631070
"""Run intent recognition portion of pipeline. Returns text to speak."""
@@ -1088,7 +1095,8 @@ async def recognize_intent(
10881095
"language": input_language,
10891096
"intent_input": intent_input,
10901097
"conversation_id": conversation_id,
1091-
"device_id": device_id,
1098+
"device_id": self._device_id,
1099+
"satellite_id": self._satellite_id,
10921100
"prefer_local_intents": self.pipeline.prefer_local_intents,
10931101
},
10941102
)
@@ -1099,7 +1107,8 @@ async def recognize_intent(
10991107
text=intent_input,
11001108
context=self.context,
11011109
conversation_id=conversation_id,
1102-
device_id=device_id,
1110+
device_id=self._device_id,
1111+
satellite_id=self._satellite_id,
11031112
language=input_language,
11041113
agent_id=self.intent_agent.id,
11051114
extra_system_prompt=conversation_extra_system_prompt,
@@ -1269,6 +1278,7 @@ async def tts_input_stream_generator() -> AsyncGenerator[str]:
12691278
text=user_input.text,
12701279
conversation_id=user_input.conversation_id,
12711280
device_id=user_input.device_id,
1281+
satellite_id=user_input.satellite_id,
12721282
context=user_input.context,
12731283
language=user_input.language,
12741284
agent_id=user_input.agent_id,
@@ -1567,10 +1577,15 @@ class PipelineInput:
15671577
device_id: str | None = None
15681578
"""Identifier of the device that is processing the input/output of the pipeline."""
15691579

1580+
satellite_id: str | None = None
1581+
"""Identifier of the satellite that is processing the input/output of the pipeline."""
1582+
15701583
async def execute(self) -> None:
15711584
"""Run pipeline."""
15721585
self.run.start(
1573-
conversation_id=self.session.conversation_id, device_id=self.device_id
1586+
conversation_id=self.session.conversation_id,
1587+
device_id=self.device_id,
1588+
satellite_id=self.satellite_id,
15741589
)
15751590
current_stage: PipelineStage | None = self.run.start_stage
15761591
stt_audio_buffer: list[EnhancedAudioChunk] = []
@@ -1656,7 +1671,6 @@ async def buffer_then_audio_stream() -> AsyncGenerator[
16561671
tts_input = await self.run.recognize_intent(
16571672
intent_input,
16581673
self.session.conversation_id,
1659-
self.device_id,
16601674
self.conversation_extra_system_prompt,
16611675
)
16621676
if tts_input.strip():

homeassistant/components/assist_satellite/entity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,7 @@ async def async_accept_pipeline_from_satellite(
522522
pipeline_id=self._resolve_pipeline(),
523523
conversation_id=session.conversation_id,
524524
device_id=device_id,
525+
satellite_id=self.entity_id,
525526
tts_audio_output=self.tts_options,
526527
wake_word_phrase=wake_word_phrase,
527528
audio_settings=AudioSettings(

homeassistant/components/conversation/agent_manager.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ async def async_converse(
7171
language: str | None = None,
7272
agent_id: str | None = None,
7373
device_id: str | None = None,
74+
satellite_id: str | None = None,
7475
extra_system_prompt: str | None = None,
7576
) -> ConversationResult:
7677
"""Process text and get intent."""
@@ -97,6 +98,7 @@ async def async_converse(
9798
context=context,
9899
conversation_id=conversation_id,
99100
device_id=device_id,
101+
satellite_id=satellite_id,
100102
language=language,
101103
agent_id=agent_id,
102104
extra_system_prompt=extra_system_prompt,

homeassistant/components/conversation/default_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ async def _async_process_intent_result(
470470
language,
471471
assistant=DOMAIN,
472472
device_id=user_input.device_id,
473+
satellite_id=user_input.satellite_id,
473474
conversation_agent_id=user_input.agent_id,
474475
)
475476
except intent.MatchFailedError as match_error:

homeassistant/components/conversation/http.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ async def websocket_hass_agent_debug(
201201
context=connection.context(msg),
202202
conversation_id=None,
203203
device_id=msg.get("device_id"),
204+
satellite_id=None,
204205
language=msg.get("language", hass.config.language),
205206
agent_id=agent.entity_id,
206207
)

homeassistant/components/conversation/models.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class ConversationInput:
3737
device_id: str | None
3838
"""Unique identifier for the device."""
3939

40+
satellite_id: str | None
41+
"""Unique identifier for the satellite."""
42+
4043
language: str
4144
"""Language of the request."""
4245

@@ -53,6 +56,7 @@ def as_dict(self) -> dict[str, Any]:
5356
"context": self.context.as_dict(),
5457
"conversation_id": self.conversation_id,
5558
"device_id": self.device_id,
59+
"satellite_id": self.satellite_id,
5660
"language": self.language,
5761
"agent_id": self.agent_id,
5862
"extra_system_prompt": self.extra_system_prompt,

homeassistant/components/conversation/trigger.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ async def call_action(
100100
entity_name: entity["value"] for entity_name, entity in details.items()
101101
},
102102
"device_id": user_input.device_id,
103+
"satellite_id": user_input.satellite_id,
103104
"user_input": user_input.as_dict(),
104105
}
105106

homeassistant/helpers/intent.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ async def async_handle(
114114
language: str | None = None,
115115
assistant: str | None = None,
116116
device_id: str | None = None,
117+
satellite_id: str | None = None,
117118
conversation_agent_id: str | None = None,
118119
) -> IntentResponse:
119120
"""Handle an intent."""
@@ -138,6 +139,7 @@ async def async_handle(
138139
language=language,
139140
assistant=assistant,
140141
device_id=device_id,
142+
satellite_id=satellite_id,
141143
conversation_agent_id=conversation_agent_id,
142144
)
143145

@@ -1276,6 +1278,7 @@ class Intent:
12761278
"intent_type",
12771279
"language",
12781280
"platform",
1281+
"satellite_id",
12791282
"slots",
12801283
"text_input",
12811284
]
@@ -1291,6 +1294,7 @@ def __init__(
12911294
language: str,
12921295
assistant: str | None = None,
12931296
device_id: str | None = None,
1297+
satellite_id: str | None = None,
12941298
conversation_agent_id: str | None = None,
12951299
) -> None:
12961300
"""Initialize an intent."""
@@ -1303,6 +1307,7 @@ def __init__(
13031307
self.language = language
13041308
self.assistant = assistant
13051309
self.device_id = device_id
1310+
self.satellite_id = satellite_id
13061311
self.conversation_agent_id = conversation_agent_id
13071312

13081313
@callback

tests/components/assist_pipeline/snapshots/test_init.ambr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
'intent_input': 'test transcript',
4646
'language': 'en',
4747
'prefer_local_intents': False,
48+
'satellite_id': None,
4849
}),
4950
'type': <PipelineEventType.INTENT_START: 'intent-start'>,
5051
}),
@@ -145,6 +146,7 @@
145146
'intent_input': 'test transcript',
146147
'language': 'en-US',
147148
'prefer_local_intents': False,
149+
'satellite_id': None,
148150
}),
149151
'type': <PipelineEventType.INTENT_START: 'intent-start'>,
150152
}),
@@ -245,6 +247,7 @@
245247
'intent_input': 'test transcript',
246248
'language': 'en-US',
247249
'prefer_local_intents': False,
250+
'satellite_id': None,
248251
}),
249252
'type': <PipelineEventType.INTENT_START: 'intent-start'>,
250253
}),
@@ -369,6 +372,7 @@
369372
'intent_input': 'test transcript',
370373
'language': 'en',
371374
'prefer_local_intents': False,
375+
'satellite_id': None,
372376
}),
373377
'type': <PipelineEventType.INTENT_START: 'intent-start'>,
374378
}),

0 commit comments

Comments
 (0)