refactor(zwave_js): hoist push event handlers to private methods - #1244
Merged
Conversation
The on_credential_changed and on_credential_deleted closures inside setup_push_subscription captured ``self`` implicitly via lexical scope. Hoisting them to private bound methods (self._on_credential_changed and self._on_credential_deleted) makes the handler surface explicit in the class layout, lets the methods participate in pyright/mypy attribute checks, and matches how the matter provider already structures its push handlers (_handle_lock_operation, _handle_lock_user_change, _dispatch_lock_user_change). Pure refactor -- handler bodies are identical, ``@callback`` decorator preserved. setup_push_subscription now wires the bound methods into self.node.on(...) registrations. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Entire-Checkpoint: 3c3130d50c41
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the Z-Wave JS provider’s push subscription setup by hoisting inline credential event-handler closures into explicit private instance methods, aligning handler structure with other providers and making the handlers easier to locate, type-check, and mock in tests.
Changes:
- Replaces the
on_credential_changed/on_credential_deletedinner@callbackclosures with bound methodsself._on_credential_changed/self._on_credential_deleted. - Keeps handler logic and
@callbackbehavior the same while simplifyingsetup_push_subscription()wiring.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1244 +/- ##
=======================================
Coverage 96.98% 96.98%
=======================================
Files 53 53
Lines 6168 6168
Branches 461 461
=======================================
Hits 5982 5982
Misses 186 186
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
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.
Proposed change
The `on_credential_changed` and `on_credential_deleted` closures inside `setup_push_subscription` captured `self` implicitly via lexical scope. Hoist them to bound private methods (`self._on_credential_changed`, `self._on_credential_deleted`) so:
Pure refactor — handler bodies are identical, `@callback` decorator preserved. The `setup_push_subscription` body now wires the bound methods directly into `self.node.on(...)` registrations.
Type of change
Test plan
🤖 Generated with Claude Code