Skip to content

Close modbus connection when HA stops - #1167

Merged
WillCodeForCats merged 1 commit into
mainfrom
1160-proper-disconnect-at-ha-restart
Oct 29, 2026
Merged

WillCodeForCats merged 1 commit into
mainfrom
1160-proper-disconnect-at-ha-restart

Conversation

@WillCodeForCats

@WillCodeForCats WillCodeForCats commented Oct 29, 2026 •

Copy link
Copy Markdown
Owner

Close modbus connection when HA stops. The entry async_on_unload() doesn't actually run for HA core shutdown or restart.

Summary by CodeRabbit

  • Bug Fixes
    • The integration now closes its connection when Home Assistant shuts down, helping ensure communication sessions do not remain open after shutdown. Connections also continue to be closed when the integration is unloaded. These changes improve connection cleanup across both shutdown and unload events.

@WillCodeForCats WillCodeForCats self-assigned this Oct 29, 2026
@WillCodeForCats WillCodeForCats linked an issue Oct 29, 2026 that may be closed by this pull request
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Walkthrough

The integration now closes its connection when Home Assistant stops. The existing unload callback remains registered.

Changes: Shutdown cleanup

Layer / File(s) Summary
Register connection cleanup on stop
custom_components/solaredge_modbus_multi/__init__.py
async_setup_entry registers a one-time stop listener that awaits connection.close(). The existing unload callback remains in place.

Priority: Low

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Possibly related issues

  • Issue 1160 reports that a Home Assistant restart leaves the inverter connection open. This change closes the connection when Home Assistant stops.
Merge Risk: Minimal · up to 5b58f

The cleanup change is ready to merge; no concrete current-head failure was established.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: closing the Modbus connection when Home Assistant stops.
Description check Passed The description states the intended change and explains why the existing unload callback is insufficient. It is brief but relevant and sufficiently complete for this focused change.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@WillCodeForCats
WillCodeForCats merged commit e2d4851 into main Oct 29, 2026
17 checks passed
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.

Proper disconnect at HA restart

1 participant