Remove PipelineEvent.as_dict (#91546)

This commit is contained in:
Erik Montnemery 2023-04-17 16:33:53 +02:00 committed by GitHub
parent 799080eb00
commit 8c1c7e1e4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 7 additions and 15 deletions

View file

@ -85,7 +85,7 @@ class PipelineEventType(StrEnum):
ERROR = "error"
@dataclass
@dataclass(frozen=True)
class PipelineEvent:
"""Events emitted during a pipeline run."""
@ -93,14 +93,6 @@ class PipelineEvent:
data: dict[str, Any] | None = None
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]

View file

@ -164,7 +164,7 @@ async def websocket_run(
pipeline=pipeline,
start_stage=start_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={
"stt_binary_handler_id": handler_id,
"timeout": timeout,

View file

@ -78,8 +78,7 @@
'type': <PipelineEventType.TTS_END: 'tts-end'>,
}),
dict({
'data': dict({
}),
'data': None,
'type': <PipelineEventType.RUN_END: 'run-end'>,
}),
])

View file

@ -1,4 +1,5 @@
"""Test Voice Assistant init."""
from dataclasses import asdict
from syrupy.assertion import SnapshotAssertion
@ -34,7 +35,7 @@ async def test_pipeline_from_audio_stream(
processed = []
for event in events:
as_dict = event.as_dict()
as_dict = asdict(event)
as_dict.pop("timestamp")
processed.append(as_dict)

View file

@ -53,7 +53,7 @@ async def test_text_only_pipeline(
# run end
msg = await client.receive_json()
assert msg["event"]["type"] == "run-end"
assert msg["event"]["data"] == {}
assert msg["event"]["data"] is None
async def test_audio_pipeline(
@ -118,7 +118,7 @@ async def test_audio_pipeline(
# run end
msg = await client.receive_json()
assert msg["event"]["type"] == "run-end"
assert msg["event"]["data"] == {}
assert msg["event"]["data"] is None
async def test_intent_timeout(