Lamarzocco fix websocket reconnect issue#156786
Merged
edenhaus merged 4 commits intoNov 19, 2025
Merged
Conversation
Co-authored-by: zweckj <24647999+zweckj@users.noreply.github.com>
Co-authored-by: zweckj <24647999+zweckj@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a websocket reconnection issue during internet outages by converting the websocket_terminated attribute to a property that checks if the background task is actually done. The fix ensures the coordinator can properly detect when the websocket task has terminated and needs to be restarted.
Key changes:
- Converted
websocket_terminatedfrom a boolean attribute to a property that checks the task'sdone()status - Added
_websocket_tasktracking to monitor the background task state - Enhanced websocket reconnection condition to check both connection status and task state
- Added test coverage for the reconnection scenario after task termination
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| homeassistant/components/lamarzocco/coordinator.py | Changed websocket_terminated from attribute to property checking task status, added _websocket_task tracking, updated reconnection logic |
| tests/components/lamarzocco/conftest.py | Updated mock_websocket_terminated fixture to use PropertyMock, added websocket mocks to mock_lamarzocco fixture |
| tests/components/lamarzocco/test_binary_sensor.py | Removed duplicate fixture definition, updated test to use shared fixture from conftest |
| tests/components/lamarzocco/test_init.py | Added new test for websocket reconnection after task termination, imported necessary utilities |
Comments suppressed due to low confidence (2)
homeassistant/components/lamarzocco/coordinator.py:117
- Multiple calls to
_internal_async_update_datacould create multiple background tasks without canceling the previous one. If the websocket reconnection logic is triggered multiple times rapidly (e.g., during network instability), this could lead to multiple concurrent websocket tasks. Consider canceling the existing_websocket_taskbefore creating a new one if it exists and is not done.
self._websocket_task = self.config_entry.async_create_background_task(
hass=self.hass,
target=self.connect_websocket(),
name="lm_websocket_task",
)
homeassistant/components/lamarzocco/coordinator.py:125
- The cleanup handlers are registered every time a websocket connection is attempted. This means if the websocket disconnects and reconnects multiple times, multiple cleanup handlers accumulate. Consider registering these handlers only once during coordinator initialization, or tracking whether they've already been registered to avoid duplication.
self.config_entry.async_on_unload(
self.hass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, websocket_close)
)
self.config_entry.async_on_unload(websocket_close)
edenhaus
approved these changes
Nov 19, 2025
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Breaking change
Proposed change
Use a property instead of an attribute to check the websocket status and also check that the task is terminated to fix an issue where during an internet outage the task would not restart as expected. Also remove a duplicate test fixture.
Type of change
Additional information
Checklist
ruff format homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all.To help with the load of incoming pull requests: