Skip to content

Model fixes for Home Assistant 2026.11 - #251

Open
mj23000 wants to merge 8 commits into
HomeAssistant-API:mainfrom
mj23000:fix/ha-2026.11-ws-models
Open

mj23000 wants to merge 8 commits into
HomeAssistant-API:mainfrom
mj23000:fix/ha-2026.11-ws-models

Conversation

@mj23000

@mj23000 mj23000 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

An array of changes have been made to the models used in the WebSocket API for Home Assistant, making the current 6.1.0 version of HomeAssistant-API no longer compatible with Home Assistant 2026.11.

This PR synchronizes the models with the ones defined in Home Assistant Core, updates the test cassettes and adds the necessary unit tests. See each commit for details.

Do note that this PR uses a patched version of nimax, that contains a necessary bug fix. This change is isolated to the latest commit, so that it can be dropped when the nimax change has been merged and released.

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@adamlogan73 adamlogan73 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this. I checked the model changes against Home Assistant core at 2026.11.3 and they line up: the entity registry output (next_name_part, no more has_entity_name, nullable aliases), the config/entity_registry/update schema (and good catch on disabled_by using the wrong enum), and the new error_reason_translation_domain on config entries. I also ran these models against a live 2026.4.3 instance and everything still parses, so older servers keep working.

A few changes before merging (details inline):

  1. Drop the vendored nimax commit (a64981c).
  2. Rebase onto main and re-record the cassettes. There are conflicts in pyproject.toml, tests/test_websocket.py and likely some cassettes. main also has a new cassette test, test_async_concurrent_listeners_and_ping in tests/test_events.py, recorded against an older HA. Please re-record the full set against 2026.11.3 after rebasing, so every cassette comes from the same version.
  3. Move the model-parsing tests to tests/test_models.py.
  4. Make next_name_part a strict enum.

Comment thread pyproject.toml Outdated
include = ["homeassistant_api", "homeassistant_api/py.typed"]

[tool.uv.sources]
nimax = { path = "vendor/nimax-1.1.1-py3-none-any.whl" }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nimax 1.2.0 includes the replay fix (nimax#8), and main now requires nimax>=1.2. Please drop this commit (a64981c). That also removes the wheel from vendor/ and the COPY vendor/ line in the Dockerfile.

Comment thread Dockerfile Outdated
FROM ghcr.io/astral-sh/uv:python3.13-bookworm AS dependencies
WORKDIR /app
COPY pyproject.toml README.md ./
COPY vendor/ ./vendor/

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line goes away with the vendored-nimax commit.

Comment thread tests/test_endpoints.py Outdated
@@ -722,3 +734,75 @@ async def test_async_get_components(async_cached_client: AsyncClient) -> None:
"""Tests the `GET /api/components` endpoint."""
components = await async_cached_client.get_components()
assert "person" in components


def test_parse_flow_progress_without_discovery_key() -> None:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test and the three after it (test_parse_flow_progress_from_older_server, test_parse_config_entry_without_nullable_fields, test_parse_flow_progress_with_non_string_placeholders) are pure model-parsing tests. Please move them to tests/test_models.py; this file holds the endpoint and cassette tests.

modified_at: DatetimeIsoField
name: str | None = None
# Values added by newer Home Assistant versions are kept as plain strings.
next_name_part: Annotated[

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this a strict NextNamePart | None. The other enums in the models are strict, and for now we would rather update the models when Home Assistant adds values than accept unknown strings in one place. If we do want unknown values to pass through, it should apply to every enum, in a separate change.

@mj23000
mj23000 force-pushed the fix/ha-2026.11-ws-models branch from a64981c to fd94fcf Compare December 3, 2026 10:28
mj23000 and others added 8 commits December 3, 2026 11:34
Home Assistant 2026.11 stopped sending `has_entity_name` in entity
registry WebSocket payloads (home-assistant/core#186898), so validating
`config/entity_registry/list`, `get` and `update` results failed.
Make the field optional so older servers keep working.

Also align the model with the current payload:
- `aliases` may mix `None` (the computed entity name) with strings
- add `next_name_part`

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- disabled_by was wrongly typed as EntityHiddenBy
- aliases may contain None for the computed entity name
- categories values may be None to remove a category from a scope
- options may be None

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- ConfigFlowContext.discovery_key is only present for discovery flows,
  so flows such as reauth failed to parse from config_entries/flow/progress
- Note that FlowContext.show_advanced_options (removed in
  home-assistant/core#172249) and ConfigFlowContext.confirm_only
  (removed in home-assistant/core#188784) are only sent by older servers
- Add ConfigFlowContext.dismiss_protected, FlowResult.sort and
  ConfigEntry.error_reason_translation_domain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
disabled_by, reason, error_reason_translation_key and
error_reason_translation_placeholders were required, so config entries
from servers that omit them failed to parse, unlike the neighbouring
error_reason_translation_domain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Home Assistant placeholder values are not guaranteed to be strings, so
error responses and flows with e.g. numeric placeholders failed to
parse. Add a shared TranslationPlaceholders type (dict[str, Any]) and
use it for all placeholder fields so new ones don't reintroduce
dict[str, str].

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Update tests for behaviour changes since 2026.4.3. The cassettes are
not re-recorded here, so these tests fail until they are:
- Two new system config entries (marketplace, analytics) bring the
  total to 6
- Disabling or enabling a config entry now sends an extra update event
  when disabled_by changes, before the entry is unloaded or set up

Give the logbook tests an entry to parse: with no history for
sun.red_sun, get_logbook_entries yielded nothing and the parsing loop
went untested. Set sun.red_sun twice before querying, since the logbook
skips an entity's initial state and the second state is what produces
an entry.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mj23000
mj23000 force-pushed the fix/ha-2026.11-ws-models branch from fd94fcf to 452ff30 Compare December 3, 2026 10:34
@mj23000

mj23000 commented Dec 4, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for the response! All your comments should be addressed now.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants