|
32 | 32 | # because push handles the real-time work. |
33 | 33 | DOP2_REFRESH_INTERVAL = 600 # seconds — hours-of-operation barely changes; we |
34 | 34 | # 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. |
35 | 37 |
|
36 | 38 |
|
37 | 39 | @dataclass |
@@ -74,6 +76,7 @@ def __init__( |
74 | 76 | self._ident_loaded = False |
75 | 77 | self._dop2_last_fetch: float = 0.0 |
76 | 78 | self._dop2_unsupported = False |
| 79 | + self._wlan_last_fetch: float = 0.0 |
77 | 80 | self._last_push_at: float | None = None |
78 | 81 | self._push_count = 0 |
79 | 82 |
|
@@ -131,19 +134,34 @@ def push_mode(self) -> str: |
131 | 134 | return "polling" |
132 | 135 |
|
133 | 136 | 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.""" |
135 | 138 | try: |
136 | 139 | state = await self.client.get_state() |
137 | 140 | self._data.state = dict(state.raw_state) |
138 | 141 | if not self._ident_loaded: |
139 | 142 | self._data.ident = await self._fetch_full_ident() |
140 | | - self._data.wlan = await self._fetch_wlan() |
141 | 143 | self._ident_loaded = True |
| 144 | + await self._maybe_refresh_wlan() |
142 | 145 | await self._maybe_refresh_dop2() |
143 | 146 | except Exception as err: # noqa: BLE001 |
144 | 147 | raise UpdateFailed(str(err)) from err |
145 | 148 | return self._data |
146 | 149 |
|
| 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 | + |
147 | 165 | async def _maybe_refresh_dop2(self) -> None: |
148 | 166 | """Refresh DOP2-sourced diagnostics for device types that expose them. |
149 | 167 |
|
|
0 commit comments