Skip to content

fix: restore pyscript state on Home Assistant 2026.11 - #883

Open
markfrancisonly wants to merge 1 commit into
custom-components:masterfrom
markfrancisonly:restore-state-ha-2026-11
Open

markfrancisonly wants to merge 1 commit into
custom-components:masterfrom
markfrancisonly:restore-state-ha-2026-11

Conversation

@markfrancisonly

Copy link
Copy Markdown

Closes #882

Home Assistant 2026.11 replaces RestoreStateData.last_states with last_states_by_entity_id and last_states_by_entity_registry_id (home-assistant/core#183906), so restore_state() raises AttributeError and pyscript fails to set up. This reads last_states_by_entity_id when it exists and falls back to last_states on older versions. Pyscript's states have no registry entry, so that dict holds all of them.

When it is needed: before Home Assistant 2026.11 reaches users. The beta is expected Wednesday 28 October and the release Wednesday 4 November. A pyscript release with this fix before then avoids an outage for everyone who upgrades.

Tested:

  • 2026.11.0.dev202610260230: without the change pyscript fails setup with the error in the issue. With it, pyscript loads, and a state.persist variable set to a new value keeps that value across a restart.
  • Pinned test requirements (Home Assistant 2026.5.0b0): ruff check, ruff format, pytest (179 passed), pylint and mypy are clean.

The test suite can exercise the new attribute only once pytest-homeassistant-custom-component publishes a 2026.11 build.

@danielbrunt57

Copy link
Copy Markdown

One caveat: this is still accessing Home Assistant's internal storage implementation, rather than a supported public API. A longer-term solution would be for Pyscript to manage its persistent entities through RestoreEntity or its own storage mechanism.

@markfrancisonly

Copy link
Copy Markdown
Author

Agreed, it's still internal, and it was before this change too: restore_state() and register_persist() in state.py both reach into RestoreStateData. This PR only keeps that working on 2026.11 so pyscript still loads after the upgrade. Moving persisted states to RestoreEntity or pyscript's own storage changes both the save and the restore path, so I've opened #885 to track that separately.

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.

Pyscript fails to set up on Home Assistant 2026.11: RestoreStateData has no attribute last_states

2 participants