1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-03 20:02:22 +01:00

Ensure we can send batches where the first message exceeds MAX_PACKET_SIZE (#9068)

This commit is contained in:
J. Nick Koston
2025-06-15 16:22:14 -05:00
committed by GitHub
parent bd85ba9b6a
commit 06810e8e6a
6 changed files with 570 additions and 5 deletions

View File

@@ -15,7 +15,7 @@ import sys
import tempfile
from typing import TextIO
from aioesphomeapi import APIClient, APIConnectionError, ReconnectLogic
from aioesphomeapi import APIClient, APIConnectionError, LogParser, ReconnectLogic
import pytest
import pytest_asyncio
@@ -365,11 +365,21 @@ async def _read_stream_lines(
stream: asyncio.StreamReader, lines: list[str], output_stream: TextIO
) -> None:
"""Read lines from a stream, append to list, and echo to output stream."""
log_parser = LogParser()
while line := await stream.readline():
decoded_line = line.decode("utf-8", errors="replace")
decoded_line = (
line.replace(b"\r", b"")
.replace(b"\n", b"")
.decode("utf8", "backslashreplace")
)
lines.append(decoded_line.rstrip())
# Echo to stdout/stderr in real-time
print(decoded_line.rstrip(), file=output_stream, flush=True)
# Print without newline to avoid double newlines
print(
log_parser.parse_line(decoded_line, timestamp=""),
file=output_stream,
flush=True,
)
@asynccontextmanager