Skip to content

Commit 445f3f9

Browse files
committed
fix(coordinator): Retry WLAN fetch until successful; refresh every 5 min
1 parent a49f75d commit 445f3f9

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

custom_components/miele_lan/coordinator.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
# because push handles the real-time work.
3333
DOP2_REFRESH_INTERVAL = 600 # seconds — hours-of-operation barely changes; we
3434
# only need to refresh ~once every 10 minutes.
35+
WLAN_REFRESH_INTERVAL = 300 # seconds — RSSI/signal-percentage drift slowly;
36+
# 5-minute cadence keeps values roughly current.
3537

3638

3739
@dataclass
@@ -74,6 +76,7 @@ def __init__(
7476
self._ident_loaded = False
7577
self._dop2_last_fetch: float = 0.0
7678
self._dop2_unsupported = False
79+
self._wlan_last_fetch: float = 0.0
7780
self._last_push_at: float | None = None
7881
self._push_count = 0
7982

@@ -131,19 +134,34 @@ def push_mode(self) -> str:
131134
return "polling"
132135

133136
async def _async_update_data(self) -> MieleLanData:
134-
"""Polled fallback: refresh /State and (once) /Ident + /WLAN."""
137+
"""Polled fallback: refresh /State and (once) /Ident; WLAN on slow cadence."""
135138
try:
136139
state = await self.client.get_state()
137140
self._data.state = dict(state.raw_state)
138141
if not self._ident_loaded:
139142
self._data.ident = await self._fetch_full_ident()
140-
self._data.wlan = await self._fetch_wlan()
141143
self._ident_loaded = True
144+
await self._maybe_refresh_wlan()
142145
await self._maybe_refresh_dop2()
143146
except Exception as err: # noqa: BLE001
144147
raise UpdateFailed(str(err)) from err
145148
return self._data
146149

150+
async def _maybe_refresh_wlan(self) -> None:
151+
"""Refresh /WLAN/ on a slow cadence, and immediately when data is absent.
152+
153+
Retry-on-empty is why this is separate from the one-shot _ident_loaded
154+
gate: a transient failure at first refresh must self-heal on the next
155+
poll without waiting WLAN_REFRESH_INTERVAL.
156+
"""
157+
now = time.monotonic()
158+
if self._data.wlan and now - self._wlan_last_fetch < WLAN_REFRESH_INTERVAL:
159+
return
160+
result = await self._fetch_wlan()
161+
if result:
162+
self._data.wlan = result
163+
self._wlan_last_fetch = now
164+
147165
async def _maybe_refresh_dop2(self) -> None:
148166
"""Refresh DOP2-sourced diagnostics for device types that expose them.
149167

0 commit comments

Comments
 (0)