Fix multiple loading of nodes#652
Merged
wollew merged 6 commits intoJulius2342:masterfrom Apr 4, 2026
Merged
Conversation
Contributor
Contributor
There was a problem hiding this comment.
Pull request overview
This PR prevents repeated PyVLX.load_nodes() calls from unnecessarily replacing Node instances (which can leave dangling callbacks), by introducing node identity matching and explicit disposal/unregistration for nodes that are replaced or removed.
Changes:
- Add
Node.dispose()andNode.represents_same_node()to support safe lifecycle management and identity matching. - Change
Nodes._load_all_nodes()/_load_node()to merge snapshots by physical identity (serial, or node_id fallback when both serials are missing) instead of always recreating nodes. - Expand unit tests to assert callback unregistration on clear/replace and identity-preserving reload behavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/pyvlx/node.py |
Adds disposal and identity helper used to preserve node instances across reloads. |
src/pyvlx/nodes.py |
Disposes replaced/cleared nodes and merges loaded snapshots to keep existing instances when appropriate. |
test/nodes_test.py |
Adds tests for disposal behavior and for identity-preserving _load_all_nodes() / _load_node() behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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.
The current code replaces instances of
Nodewith new instances every timePyVLX.load_nodes()is called, even when the actual the device in the gateway didn't change. This leaves dangling callbacks and potentially leaks memory. This PR changes the code that gateway devices which are considered "physically the same device" (=either identical serial number or no serial number available but identical node id) do not generate new node instances.Multiple calls to
PyVLX.load_nodes()will be necessary in order to fulfill HA's "dynamic devices" quality scale rule.