Remove PipelineEvent.as_dict (#91546)
This commit is contained in:
parent
799080eb00
commit
8c1c7e1e4c
5 changed files with 7 additions and 15 deletions
|
@ -85,7 +85,7 @@ class PipelineEventType(StrEnum):
|
||||||
ERROR = "error"
|
ERROR = "error"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass(frozen=True)
|
||||||
class PipelineEvent:
|
class PipelineEvent:
|
||||||
"""Events emitted during a pipeline run."""
|
"""Events emitted during a pipeline run."""
|
||||||
|
|
||||||
|
@ -93,14 +93,6 @@ class PipelineEvent:
|
||||||
data: dict[str, Any] | None = None
|
data: dict[str, Any] | None = None
|
||||||
timestamp: str = field(default_factory=lambda: dt_util.utcnow().isoformat())
|
timestamp: str = field(default_factory=lambda: dt_util.utcnow().isoformat())
|
||||||
|
|
||||||
def as_dict(self) -> dict[str, Any]:
|
|
||||||
"""Return a dict representation of the event."""
|
|
||||||
return {
|
|
||||||
"type": self.type,
|
|
||||||
"timestamp": self.timestamp,
|
|
||||||
"data": self.data or {},
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
PipelineEventCallback = Callable[[PipelineEvent], None]
|
PipelineEventCallback = Callable[[PipelineEvent], None]
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ async def websocket_run(
|
||||||
pipeline=pipeline,
|
pipeline=pipeline,
|
||||||
start_stage=start_stage,
|
start_stage=start_stage,
|
||||||
end_stage=end_stage,
|
end_stage=end_stage,
|
||||||
event_callback=lambda event: connection.send_event(msg["id"], event.as_dict()),
|
event_callback=lambda event: connection.send_event(msg["id"], event),
|
||||||
runner_data={
|
runner_data={
|
||||||
"stt_binary_handler_id": handler_id,
|
"stt_binary_handler_id": handler_id,
|
||||||
"timeout": timeout,
|
"timeout": timeout,
|
||||||
|
|
|
@ -78,8 +78,7 @@
|
||||||
'type': <PipelineEventType.TTS_END: 'tts-end'>,
|
'type': <PipelineEventType.TTS_END: 'tts-end'>,
|
||||||
}),
|
}),
|
||||||
dict({
|
dict({
|
||||||
'data': dict({
|
'data': None,
|
||||||
}),
|
|
||||||
'type': <PipelineEventType.RUN_END: 'run-end'>,
|
'type': <PipelineEventType.RUN_END: 'run-end'>,
|
||||||
}),
|
}),
|
||||||
])
|
])
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
"""Test Voice Assistant init."""
|
"""Test Voice Assistant init."""
|
||||||
|
from dataclasses import asdict
|
||||||
|
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ async def test_pipeline_from_audio_stream(
|
||||||
|
|
||||||
processed = []
|
processed = []
|
||||||
for event in events:
|
for event in events:
|
||||||
as_dict = event.as_dict()
|
as_dict = asdict(event)
|
||||||
as_dict.pop("timestamp")
|
as_dict.pop("timestamp")
|
||||||
processed.append(as_dict)
|
processed.append(as_dict)
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,7 @@ async def test_text_only_pipeline(
|
||||||
# run end
|
# run end
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
assert msg["event"]["type"] == "run-end"
|
assert msg["event"]["type"] == "run-end"
|
||||||
assert msg["event"]["data"] == {}
|
assert msg["event"]["data"] is None
|
||||||
|
|
||||||
|
|
||||||
async def test_audio_pipeline(
|
async def test_audio_pipeline(
|
||||||
|
@ -118,7 +118,7 @@ async def test_audio_pipeline(
|
||||||
# run end
|
# run end
|
||||||
msg = await client.receive_json()
|
msg = await client.receive_json()
|
||||||
assert msg["event"]["type"] == "run-end"
|
assert msg["event"]["type"] == "run-end"
|
||||||
assert msg["event"]["data"] == {}
|
assert msg["event"]["data"] is None
|
||||||
|
|
||||||
|
|
||||||
async def test_intent_timeout(
|
async def test_intent_timeout(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue