Repository navigation
Conversation
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]>
Contributor
Author
|
Oops just noticed #883 will close this in favor of that one |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On HA 2026.11.0b1, pyscript fails to set up with:
HA 2026.11 replaced
RestoreStateData.last_stateswith two dicts. Stored states are now split by whether the entity has an entity registry entry:last_states_by_entity_idholds entities with no registry entrylast_states_by_entity_registry_idholds entities that have onerestore_state()reads these HA internals directly, so it broke.Persisted pyscript variables are backed by a bare
PyscriptEntitythat never has a registry entry. HA dumps them withentity_registry_id=None, so they always land inlast_states_by_entity_id. This PR reads that dict and falls back tolast_stateson 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
test_restore_state, which checks thatpyscript.*states and their attributes are restored and that other domains are ignored.pytest-homeassistant-custom-componentrelease supports 2026.11 yet, so I checked against HA 2026.11.0b1 with a standalone script that loads stored states through the realRestoreStateData. 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