Compare commits
9
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b4e96adf9c | ||
|
|
0ccf787dc6 | ||
|
|
e033ad2ad5 | ||
|
|
b000579533 | ||
|
|
d00f4ea173 | ||
|
|
f2ff73ea31 | ||
|
|
602fe7b220 | ||
|
|
840bdeb87d | ||
|
|
b629251905 |
@@ -1,5 +1,94 @@
|
||||
# NestQuest Release Notes
|
||||
|
||||
## Version 0.10.1 — 2026-10-06
|
||||
|
||||
### Scope
|
||||
|
||||
Patch release carrying the panel SSE stream fix onto `main` (PR #295, task
|
||||
4cbf2e96).
|
||||
|
||||
### Behaviour
|
||||
|
||||
- The Home Assistant integration now reads the panel event stream from the
|
||||
response body (`response.content`), fixing the logged failure
|
||||
`'async for' requires an object with __aiter__ method, got HassClientResponse`
|
||||
that logged ~935 times and prevented live panel events (completions,
|
||||
un-completions, day-complete, missed) from re-firing from the API's SSE
|
||||
stream. SSE line-buffering and JSON-frame parsing are unchanged.
|
||||
|
||||
### Requirements
|
||||
|
||||
- Home Assistant floor 2024.6.0 (unchanged).
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- None. Schema unchanged at version 9; no migration, no database backup
|
||||
required.
|
||||
|
||||
### Known limitations
|
||||
|
||||
- Intermittent `GET /api/v1/panel/events failed with HTTP 502` during API
|
||||
restarts/redeploys is expected (the integration reconnects with backoff).
|
||||
- The event stream still reconnects periodically because Home Assistant's
|
||||
shared aiohttp session applies a default total timeout — tracked as a
|
||||
follow-up; it does not affect correctness.
|
||||
|
||||
### Rollback
|
||||
|
||||
- No schema change: rolling back to 0.10.0 requires no database restore.
|
||||
|
||||
## Version 0.10.0 — 2026-09-30
|
||||
|
||||
### Scope
|
||||
|
||||
Feature release: choose task icons by typing any Font Awesome Free **solid**
|
||||
icon name, not just the curated subset. The shared icon registry now embeds the
|
||||
full Font Awesome Free solid set offline (no CDN — the panel may be offline),
|
||||
the admin icon picker is searchable with free-text entry and validation, and the
|
||||
kids' panel renders any Free Solid icon. (Feature `6c681b17`; PRs #289–#292.)
|
||||
|
||||
### Behaviour
|
||||
|
||||
- **Full Free Solid set**: the panel and admin bundles now carry ~1,422 Font
|
||||
Awesome Free solid glyphs as inline SVG path data, in addition to the existing
|
||||
curated quick-pick lists (Lucide and Font Awesome). `fa:<name>` resolves any
|
||||
Free Solid icon; unknown names still render the fallback glyph.
|
||||
- **Searchable picker**: the admin definition icon picker's Font Awesome tab has
|
||||
a search input. Empty shows the curated quick picks; typing filters the full
|
||||
set into a bounded (≤40 per page) result grid, with Previous / Show more.
|
||||
- **Free-text entry**: typing an exact Free Solid name selects and stores
|
||||
`fa:<name>`. A partial, misspelled, Pro, or Brands name is rejected with an
|
||||
inline message and nothing is saved.
|
||||
- Stored format is unchanged: `lucide:<name>`, `fa:<name>`, `emoji:<grapheme>`,
|
||||
or a legacy bare name.
|
||||
|
||||
### Requirements
|
||||
|
||||
- Home Assistant floor 2024.6.0 (unchanged).
|
||||
|
||||
### Breaking changes
|
||||
|
||||
- None to the database: schema unchanged at version 9, no migration and no
|
||||
database backup required.
|
||||
- Font Awesome **Pro** and **Brands/Regular** icons are NOT included — only the
|
||||
Free Solid set. A Pro/Brands name is rejected in the picker (and an unknown
|
||||
`fa:` name falls back on the panel).
|
||||
|
||||
### Known limitations
|
||||
|
||||
- **Bundle size**: the embedded icon set increases the committed panel bundle to
|
||||
~1.06 MB raw (~276 kB gzip) and the admin PWA bundle similarly. This is
|
||||
expected for the full Free Solid set.
|
||||
- Alias names (e.g. Font Awesome's `fa:home` alias of `fa:house`) are
|
||||
de-duplicated to the canonical name, so `fa:house` resolves but `fa:home`
|
||||
falls back.
|
||||
- The backend still validates only the `fa:<kebab-name>` format; unknown names
|
||||
are caught in the picker and render as the fallback on the panel.
|
||||
|
||||
### Rollback
|
||||
|
||||
- No schema change: rolling back to 0.9.8 requires no database restore.
|
||||
|
||||
## Version 0.9.8 — 2026-09-30
|
||||
|
||||
### Scope
|
||||
|
||||
@@ -16,9 +16,11 @@ network and NO aiohttp installed; production builds the client through
|
||||
:func:`client_from_entry`, which hands in Home Assistant's shared
|
||||
aiohttp session (``homeassistant.helpers.aiohttp_client
|
||||
.async_get_clientsession``). The module itself imports NEITHER
|
||||
homeassistant NOR aiohttp at runtime (aiohttp appears only behind
|
||||
``TYPE_CHECKING`` for annotations), so the client is usable anywhere —
|
||||
the HA coupling lives in the one production factory.
|
||||
homeassistant NOR aiohttp at module import (aiohttp appears only
|
||||
behind ``TYPE_CHECKING`` for annotations, plus one lazy import inside
|
||||
:meth:`NestQuestApiClient.stream_events` for its ``ClientTimeout``), so
|
||||
the client is importable anywhere — the HA coupling lives in the one
|
||||
production factory.
|
||||
|
||||
Every failure is typed: a transport failure (connection refused, DNS
|
||||
failure, timeout — the exchange never produced a response) and every
|
||||
@@ -38,7 +40,11 @@ frame (``event: <type>`` / ``data: <json>`` lines separated by a blank
|
||||
line). Opening the stream gets the same one-timeout, typed-error
|
||||
contract as every other call; reading it has NO body-wide timeout (a
|
||||
healthy stream is long-lived — the subscription manager owns
|
||||
reconnection and backoff).
|
||||
reconnection and backoff). That includes the session's own default:
|
||||
Home Assistant's shared session carries ``ClientTimeout(total=300)``,
|
||||
which would cut a healthy stream every five minutes, so the stream
|
||||
request overrides it with ``total=None`` (keeping a finite
|
||||
``sock_connect``).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
|
||||
@@ -278,8 +284,19 @@ class NestQuestApiClient:
|
||||
(``aclose``, i.e. the consumer's task being cancelled) stops
|
||||
cleanly and closes the underlying response in every path.
|
||||
"""
|
||||
# Lazy: aiohttp ships with Home Assistant, but importing it at
|
||||
# module level would make the client unimportable without it.
|
||||
import aiohttp
|
||||
|
||||
url = f"{self._base_url}{EVENTS_PATH}"
|
||||
headers = self._headers()
|
||||
# The session's default total timeout (HA's shared session:
|
||||
# 300 s) would cut a healthy stream mid-body, and events fired
|
||||
# while reconnecting are not replayed — so the stream request
|
||||
# is unbounded in total time; only connecting stays bounded.
|
||||
stream_timeout = aiohttp.ClientTimeout(
|
||||
total=None, sock_connect=self._timeout_seconds
|
||||
)
|
||||
# Opening the response gets ONE request timeout, exactly like
|
||||
# ``_request_json``; the read loop below runs WITHOUT one — a
|
||||
# body-wide timeout would kill a healthy long-lived stream.
|
||||
@@ -289,7 +306,7 @@ class NestQuestApiClient:
|
||||
try:
|
||||
async with asyncio.timeout(self._timeout_seconds):
|
||||
stream_cm = self._session.request(
|
||||
"GET", url, headers=headers, json=None
|
||||
"GET", url, headers=headers, json=None, timeout=stream_timeout
|
||||
)
|
||||
response = await stream_cm.__aenter__()
|
||||
except asyncio.CancelledError:
|
||||
@@ -315,7 +332,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
|
||||
|
||||
@@ -15,5 +15,5 @@
|
||||
"iot_class": "local_polling",
|
||||
"issue_tracker": "https://github.com/Maniacs-Mansion/NestQuest/issues",
|
||||
"requirements": [],
|
||||
"version": "0.9.8"
|
||||
"version": "0.10.1"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "nestquest"
|
||||
version = "0.9.8"
|
||||
version = "0.10.1"
|
||||
description = "NestQuest Home Assistant Integration"
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.11"
|
||||
|
||||
@@ -879,6 +879,29 @@ def set_coordinator_client(entry, client):
|
||||
return client
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class FakeClientTimeout:
|
||||
"""Stand-in for ``aiohttp.ClientTimeout`` (the fields the client sets)."""
|
||||
|
||||
total: float | None = None
|
||||
sock_connect: float | None = None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def fake_aiohttp(monkeypatch):
|
||||
"""Install a stand-in ``aiohttp`` module for one test.
|
||||
|
||||
aiohttp ships only with Home Assistant, so this mock-only harness
|
||||
does not have it; the API client imports it lazily inside
|
||||
``stream_events`` (for ``ClientTimeout``). Tests driving the real
|
||||
stream path request this fixture; the module is removed again when
|
||||
the test ends.
|
||||
"""
|
||||
module = SimpleNamespace(ClientTimeout=FakeClientTimeout)
|
||||
monkeypatch.setitem(sys.modules, "aiohttp", module)
|
||||
return module
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def coordinator_client_from_test_override():
|
||||
"""Resolve every entry's coordinator client through the test seam.
|
||||
|
||||
+112
-2
@@ -17,7 +17,7 @@ import types
|
||||
|
||||
import pytest
|
||||
|
||||
from conftest import make_config_entry
|
||||
from conftest import FakeClientTimeout, make_config_entry
|
||||
|
||||
from custom_components.nestquest import api_client
|
||||
from custom_components.nestquest.api_client import (
|
||||
@@ -33,6 +33,10 @@ from custom_components.nestquest.const import (
|
||||
DEFAULT_PANEL_TOKEN,
|
||||
)
|
||||
|
||||
# ``stream_events`` imports aiohttp lazily; the harness has none, so
|
||||
# every test here runs with the stand-in module installed.
|
||||
pytestmark = pytest.mark.usefixtures("fake_aiohttp")
|
||||
|
||||
BASE_URL = "http://api.test:8000"
|
||||
TOKEN = "test-panel-token"
|
||||
|
||||
@@ -124,6 +128,7 @@ class StubTransport:
|
||||
"url": url,
|
||||
"headers": kwargs.get("headers"),
|
||||
"json": kwargs.get("json"),
|
||||
"timeout": kwargs.get("timeout"),
|
||||
}
|
||||
)
|
||||
if not self._outcomes:
|
||||
@@ -472,4 +477,109 @@ async def test_client_logs_nothing() -> None:
|
||||
await client.get_snapshot()
|
||||
finally:
|
||||
logging.getLogger().removeHandler(handler)
|
||||
assert records == []
|
||||
assert records == []
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# stream_events: the body is read from ``response.content``
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
class _StubStreamContent:
|
||||
"""A fake aiohttp ``StreamReader``: async-iterable over byte chunks."""
|
||||
|
||||
def __init__(self, chunks) -> None:
|
||||
self._chunks = list(chunks)
|
||||
|
||||
def __aiter__(self):
|
||||
return self._iterate()
|
||||
|
||||
async def _iterate(self):
|
||||
for chunk in self._chunks:
|
||||
yield chunk
|
||||
|
||||
|
||||
class StubStreamResponse:
|
||||
"""A fake aiohttp/HA ``ClientResponse`` for a streaming body.
|
||||
|
||||
Like the real ``HassClientResponse`` it does NOT implement
|
||||
``__aiter__`` — the body is iterated through ``.content`` — so a
|
||||
client that iterates the response object itself raises the
|
||||
``'async for' requires an object with __aiter__ method`` TypeError.
|
||||
"""
|
||||
|
||||
def __init__(self, status: int, chunks) -> None:
|
||||
self.status = status
|
||||
self.content = _StubStreamContent(chunks)
|
||||
|
||||
|
||||
async def test_stream_events_reads_frames_from_response_content() -> None:
|
||||
"""Frames are parsed from ``response.content`` byte chunks, including
|
||||
a frame split across chunk boundaries; a trailing incomplete frame
|
||||
is discarded."""
|
||||
assert not hasattr(StubStreamResponse, "__aiter__")
|
||||
chunks = [
|
||||
b'event: nestquest_quest_completed\ndata: {"instance_id"',
|
||||
b': 7}\n',
|
||||
b'\nevent: nestquest_child_day_complete\n',
|
||||
b'data: {"child_id": 1}\n\n',
|
||||
b'event: nestquest_quest_missed\ndata: {"instance_id": 9}\n',
|
||||
]
|
||||
transport = StubTransport(StubStreamResponse(200, chunks))
|
||||
client = make_client(transport)
|
||||
|
||||
frames = [frame async for frame in client.stream_events()]
|
||||
|
||||
assert frames == [
|
||||
("nestquest_quest_completed", {"instance_id": 7}),
|
||||
("nestquest_child_day_complete", {"child_id": 1}),
|
||||
]
|
||||
assert transport.calls[0]["method"] == "GET"
|
||||
assert transport.calls[0]["url"] == f"{BASE_URL}/api/v1/panel/events"
|
||||
|
||||
|
||||
async def test_stream_events_non_2xx_raises_typed_with_status() -> None:
|
||||
transport = StubTransport(StubStreamResponse(502, []))
|
||||
client = make_client(transport)
|
||||
|
||||
with pytest.raises(NestQuestApiError) as excinfo:
|
||||
async for _ in client.stream_events():
|
||||
pass
|
||||
|
||||
assert excinfo.value.status == 502
|
||||
assert not excinfo.value.is_transport_error
|
||||
|
||||
|
||||
async def test_stream_events_invalid_json_frame_raises_typed() -> None:
|
||||
transport = StubTransport(
|
||||
StubStreamResponse(200, [b"event: nestquest_quest_completed\n", b"data: {nope\n\n"])
|
||||
)
|
||||
client = make_client(transport)
|
||||
|
||||
with pytest.raises(NestQuestApiError) as excinfo:
|
||||
async for _ in client.stream_events():
|
||||
pass
|
||||
|
||||
assert excinfo.value.status == 200
|
||||
assert not excinfo.value.is_transport_error
|
||||
assert isinstance(excinfo.value.__cause__, ValueError)
|
||||
|
||||
|
||||
async def test_stream_events_disables_the_session_total_timeout() -> None:
|
||||
"""The stream request overrides the session's default total timeout
|
||||
(HA's shared session: 300 s, which would cut a healthy stream) with
|
||||
``total=None`` while keeping a finite connect timeout; the plain
|
||||
request calls pass no per-request timeout."""
|
||||
transport = StubTransport(
|
||||
StubStreamResponse(200, []), StubResponse(200, json.dumps(SNAPSHOT_PAYLOAD))
|
||||
)
|
||||
client = make_client(transport, timeout_seconds=7.0)
|
||||
|
||||
frames = [frame async for frame in client.stream_events()]
|
||||
await client.get_snapshot()
|
||||
|
||||
assert frames == []
|
||||
stream_timeout = transport.calls[0]["timeout"]
|
||||
assert isinstance(stream_timeout, FakeClientTimeout)
|
||||
assert stream_timeout.total is None
|
||||
assert stream_timeout.sock_connect == 7.0
|
||||
assert transport.calls[1]["timeout"] is None
|
||||
|
||||
@@ -44,6 +44,10 @@ from custom_components.nestquest.api_client import (
|
||||
)
|
||||
from custom_components.nestquest.sse import NestQuestEventStream
|
||||
|
||||
# ``stream_events`` imports aiohttp lazily; the harness has none, so
|
||||
# every test here runs with the stand-in module installed.
|
||||
pytestmark = pytest.mark.usefixtures("fake_aiohttp")
|
||||
|
||||
BASE_URL = "http://api.test:8000"
|
||||
TOKEN = "test-panel-token"
|
||||
|
||||
@@ -165,19 +169,29 @@ MINIMAL_SNAPSHOT = {
|
||||
|
||||
|
||||
class _StreamingResponse:
|
||||
"""A fake aiohttp streaming response: ``status`` + chunk iteration.
|
||||
"""A fake aiohttp streaming response: ``status`` + ``.content``.
|
||||
|
||||
``chunks`` are the body pieces the stream yields in order; a chunk
|
||||
may be an exception, raised when the iteration reaches it (a
|
||||
mid-stream transport drop). ``hold_open`` keeps the stream open
|
||||
forever after the chunks run out, for cancellation tests.
|
||||
Like aiohttp's ``ClientResponse`` (and HA's ``HassClientResponse``)
|
||||
the response itself is NOT async-iterable; the body is iterated
|
||||
through ``.content``. ``chunks`` are the body pieces the stream
|
||||
yields in order; a chunk may be an exception, raised when the
|
||||
iteration reaches it (a mid-stream transport drop). ``hold_open``
|
||||
keeps the stream open forever after the chunks run out, for
|
||||
cancellation tests.
|
||||
"""
|
||||
|
||||
def __init__(self, status: int, chunks, *, hold_open: bool = False) -> None:
|
||||
self.status = status
|
||||
self.content = _StreamingContent(chunks, hold_open)
|
||||
self.closed = False
|
||||
|
||||
|
||||
class _StreamingContent:
|
||||
"""The fake response body: an async-iterable chunk stream."""
|
||||
|
||||
def __init__(self, chunks, hold_open: bool) -> None:
|
||||
self._chunks = list(chunks)
|
||||
self._hold_open = hold_open
|
||||
self.closed = False
|
||||
|
||||
def __aiter__(self):
|
||||
return self._iterate()
|
||||
|
||||
Reference in New Issue
Block a user