Skip to content

Fix restore_state for HA 2026.11 RestoreStateData changes - #884

Closed
raman325 wants to merge 1 commit into
custom-components:masterfrom
raman325:fix-restore-state-last-states
Closed

raman325 wants to merge 1 commit into
custom-components:masterfrom
raman325:fix-restore-state-last-states

Conversation

@raman325

Copy link
Copy Markdown
Contributor

Summary

On HA 2026.11.0b1, pyscript fails to set up with:

Error during setup of component pyscript: 'RestoreStateData' object has no attribute 'last_states'

HA 2026.11 replaced RestoreStateData.last_states with two dicts. Stored states are now split by whether the entity has an entity registry entry:

  • last_states_by_entity_id holds entities with no registry entry
  • last_states_by_entity_registry_id holds entities that have one

restore_state() reads these HA internals directly, so it broke.

Persisted pyscript variables are backed by a bare PyscriptEntity that never has a registry entry. HA dumps them with entity_registry_id=None, so they always land in last_states_by_entity_id. This PR reads that dict and falls back to last_states on older HA versions, the same version-fallback approach used for the template helper imports.

The save path (register_persist → async_restore_entity_added) is unchanged in HA, so only the read side needed a fix.

Testing

  • Added test_restore_state, which checks that pyscript.* states and their attributes are restored and that other domains are ignored.
  • Full test suite passes on the pinned HA version.
  • No pytest-homeassistant-custom-component release supports 2026.11 yet, so I checked against HA 2026.11.0b1 with a standalone script that loads stored states through the real RestoreStateData. It reproduces the error without this change and passes with it. On the current pin, the new test only covers the pre-2026.11 code path; it will cover the new one once the test requirements are bumped.

🤖 Generated with Claude Code

HA 2026.11 replaced RestoreStateData.last_states with
last_states_by_entity_id and last_states_by_entity_registry_id, which
broke pyscript setup with "'RestoreStateData' object has no attribute
'last_states'". Persisted pyscript variables have no entity registry
entry, so read last_states_by_entity_id, falling back to last_states on
older HA versions.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 03:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@raman325

Copy link
Copy Markdown
Contributor Author

Oops just noticed #883 will close this in favor of that one

@raman325 raman325 closed this Oct 30, 2026
@raman325
raman325 deleted the fix-restore-state-last-states branch October 30, 2026 03:29
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