Allow lamarzocco to reconnect websocket (#133635)

This commit is contained in:
Josef Zweck 2024-12-21 11:29:24 +01:00 committed by GitHub
parent 78c9e47428
commit 66e863a2e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 3 deletions

View File

@ -91,9 +91,11 @@ class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator):
_scale_address: str | None = None
async def _async_setup(self) -> None:
async def _async_connect_websocket(self) -> None:
"""Set up the coordinator."""
if self._local_client is not None:
if self._local_client is not None and (
self._local_client.websocket is None or self._local_client.websocket.closed
):
_LOGGER.debug("Init WebSocket in background task")
self.config_entry.async_create_background_task(
@ -123,6 +125,7 @@ class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator):
"""Fetch data from API endpoint."""
await self.device.get_config()
_LOGGER.debug("Current status: %s", str(self.device.config))
await self._async_connect_websocket()
self._async_add_remove_scale()
@callback

View File

@ -199,8 +199,11 @@ async def test_websocket_closed_on_unload(
) as local_client:
client = local_client.return_value
client.websocket = AsyncMock()
client.websocket.closed = False
await async_init_integration(hass, mock_config_entry)
mock_lamarzocco.websocket_connect.assert_called_once()
client.websocket.closed = False
hass.bus.async_fire(EVENT_HOMEASSISTANT_STOP)
await hass.async_block_till_done()
client.websocket.close.assert_called_once()