Read the panel SSE body from response.content (task 4cbf2e96)
stream_events iterated the aiohttp/HA ClientResponse itself, which is not async-iterable, so every panel event stream died with "'async for' requires an object with __aiter__ method, got HassClientResponse" and reconnected forever. Iterate response.content (the StreamReader) instead; parsing, close, and the error/retry contract are unchanged. The streaming test stub in test_sse_subscription.py made the same mistake (it implemented __aiter__ on the response), which is why the suite never caught this; it now exposes .content like the real response. New test_api_client.py tests use a response without __aiter__ and byte chunks split across frame boundaries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -315,7 +315,10 @@ class NestQuestApiClient:
|
||||
event_type: str | None = None
|
||||
data_lines: list[str] = []
|
||||
buffer = ""
|
||||
async for chunk in response:
|
||||
# The body is ``response.content`` (aiohttp's StreamReader,
|
||||
# yielding bytes); the response object itself — HA's
|
||||
# ``HassClientResponse`` included — is NOT async-iterable.
|
||||
async for chunk in response.content:
|
||||
if isinstance(chunk, (bytes, bytearray)):
|
||||
chunk = chunk.decode("utf-8")
|
||||
buffer += chunk
|
||||
|
||||
Reference in New Issue
Block a user