Change lamarzocco general update frequency (#143417)

This commit is contained in:
Josef Zweck 2025-04-22 12:52:27 +02:00 committed by GitHub
parent 0b64151ae0
commit def11f9959
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 26 deletions

View File

@ -19,7 +19,7 @@ from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, Upda
from .const import DOMAIN
SCAN_INTERVAL = timedelta(seconds=30)
SCAN_INTERVAL = timedelta(seconds=15)
SETTINGS_UPDATE_INTERVAL = timedelta(hours=1)
SCHEDULE_UPDATE_INTERVAL = timedelta(minutes=5)
_LOGGER = logging.getLogger(__name__)
@ -82,35 +82,32 @@ class LaMarzoccoUpdateCoordinator(DataUpdateCoordinator[None]):
class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator):
"""Class to handle fetching data from the La Marzocco API centrally."""
async def _async_connect_websocket(self) -> None:
"""Set up the coordinator."""
if not self.device.websocket.connected:
_LOGGER.debug("Init WebSocket in background task")
self.config_entry.async_create_background_task(
hass=self.hass,
target=self.device.connect_dashboard_websocket(
update_callback=lambda _: self.async_set_updated_data(None)
),
name="lm_websocket_task",
)
async def websocket_close(_: Any | None = None) -> None:
if self.device.websocket.connected:
await self.device.websocket.disconnect()
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)
async def _internal_async_update_data(self) -> None:
"""Fetch data from API endpoint."""
if self.device.websocket.connected:
return
await self.device.get_dashboard()
_LOGGER.debug("Current status: %s", self.device.dashboard.to_dict())
await self._async_connect_websocket()
_LOGGER.debug("Init WebSocket in background task")
self.config_entry.async_create_background_task(
hass=self.hass,
target=self.device.connect_dashboard_websocket(
update_callback=lambda _: self.async_set_updated_data(None)
),
name="lm_websocket_task",
)
async def websocket_close(_: Any | None = None) -> None:
if self.device.websocket.connected:
await self.device.websocket.disconnect()
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)
class LaMarzoccoSettingsUpdateCoordinator(LaMarzoccoUpdateCoordinator):

View File

@ -65,6 +65,7 @@ async def test_sensor_going_unavailable(
assert state
assert state.state != STATE_UNAVAILABLE
mock_lamarzocco.websocket.connected = False
mock_lamarzocco.get_dashboard.side_effect = RequestNotSuccessful("")
freezer.tick(timedelta(minutes=10))
async_fire_time_changed(hass)

View File

@ -53,6 +53,7 @@ async def test_config_entry_not_ready(
mock_lamarzocco: MagicMock,
) -> None:
"""Test the La Marzocco configuration entry not ready."""
mock_lamarzocco.websocket.connected = False
mock_lamarzocco.get_dashboard.side_effect = RequestNotSuccessful("")
await async_init_integration(hass, mock_config_entry)
@ -90,6 +91,7 @@ async def test_invalid_auth(
mock_lamarzocco: MagicMock,
) -> None:
"""Test auth error during setup."""
mock_lamarzocco.websocket.connected = False
mock_lamarzocco.get_dashboard.side_effect = AuthFail("")
await async_init_integration(hass, mock_config_entry)