Skip to content

Commit dd01243

Browse files
zweckjfrenck
authored andcommitted
Ensure token validity in lamarzocco (home-assistant#153058)
1 parent 66c17e2 commit dd01243

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

homeassistant/components/lamarzocco/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) -
142142
)
143143

144144
coordinators = LaMarzoccoRuntimeData(
145-
LaMarzoccoConfigUpdateCoordinator(hass, entry, device),
145+
LaMarzoccoConfigUpdateCoordinator(hass, entry, device, cloud_client),
146146
LaMarzoccoSettingsUpdateCoordinator(hass, entry, device),
147147
LaMarzoccoScheduleUpdateCoordinator(hass, entry, device),
148148
LaMarzoccoStatisticsUpdateCoordinator(hass, entry, device),

homeassistant/components/lamarzocco/coordinator.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import logging
99
from typing import Any
1010

11-
from pylamarzocco import LaMarzoccoMachine
11+
from pylamarzocco import LaMarzoccoCloudClient, LaMarzoccoMachine
1212
from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful
1313

1414
from homeassistant.config_entries import ConfigEntry
@@ -19,7 +19,7 @@
1919

2020
from .const import DOMAIN
2121

22-
SCAN_INTERVAL = timedelta(seconds=15)
22+
SCAN_INTERVAL = timedelta(seconds=60)
2323
SETTINGS_UPDATE_INTERVAL = timedelta(hours=8)
2424
SCHEDULE_UPDATE_INTERVAL = timedelta(minutes=30)
2525
STATISTICS_UPDATE_INTERVAL = timedelta(minutes=15)
@@ -51,6 +51,7 @@ def __init__(
5151
hass: HomeAssistant,
5252
entry: LaMarzoccoConfigEntry,
5353
device: LaMarzoccoMachine,
54+
cloud_client: LaMarzoccoCloudClient | None = None,
5455
) -> None:
5556
"""Initialize coordinator."""
5657
super().__init__(
@@ -61,6 +62,7 @@ def __init__(
6162
update_interval=self._default_update_interval,
6263
)
6364
self.device = device
65+
self.cloud_client = cloud_client
6466

6567
async def _async_update_data(self) -> None:
6668
"""Do the data update."""
@@ -85,11 +87,17 @@ async def _internal_async_update_data(self) -> None:
8587
class LaMarzoccoConfigUpdateCoordinator(LaMarzoccoUpdateCoordinator):
8688
"""Class to handle fetching data from the La Marzocco API centrally."""
8789

90+
cloud_client: LaMarzoccoCloudClient
91+
8892
async def _internal_async_update_data(self) -> None:
8993
"""Fetch data from API endpoint."""
9094

95+
# ensure token stays valid; does nothing if token is still valid
96+
await self.cloud_client.async_get_access_token()
97+
9198
if self.device.websocket.connected:
9299
return
100+
93101
await self.device.get_dashboard()
94102
_LOGGER.debug("Current status: %s", self.device.dashboard.to_dict())
95103

0 commit comments

Comments
 (0)