Skip to content

Commit dce6df4

Browse files
authored
Fall back to global client_list query when per-node returns 5xx (#527)
1 parent ff5b414 commit dce6df4

1 file changed

Lines changed: 26 additions & 7 deletions

File tree

custom_components/tplink_deco/coordinator.py

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

11+
import aiohttp
12+
1113
from homeassistant.config_entries import ConfigEntry
1214
from homeassistant.core import CALLBACK_TYPE
1315
from homeassistant.core import HomeAssistant
@@ -315,14 +317,31 @@ async def _async_update_data(self):
315317
utc_point_in_time = dt_util.utcnow()
316318
# Send list client requests in parallel for each deco
317319

318-
deco_client_responses = await asyncio.gather(
319-
*[
320-
async_call_and_propagate_config_error(
321-
self.api.async_list_clients, deco_mac
322-
)
323-
for deco_mac in deco_macs
320+
try:
321+
deco_client_responses = await asyncio.gather(
322+
*[
323+
async_call_and_propagate_config_error(
324+
self.api.async_list_clients, deco_mac
325+
)
326+
for deco_mac in deco_macs
327+
]
328+
)
329+
except aiohttp.ClientResponseError as err:
330+
if err.status < 500:
331+
raise
332+
# Some Deco firmware (e.g. XE75 1.3.x) returns a 5xx (502 observed)
333+
# for the per-node client_list query. Fall back to a single global
334+
# query and attribute every client to the master Deco, so its
335+
# client-count sensor reflects the whole mesh (satellites report 0).
336+
_LOGGER.debug(
337+
"Per-node client_list failed (%s); falling back to global query",
338+
err,
339+
)
340+
master_deco = self._deco_update_coordinator.data.master_deco
341+
deco_macs = [master_deco.mac if master_deco is not None else "default"]
342+
deco_client_responses = [
343+
await async_call_and_propagate_config_error(self.api.async_list_clients)
324344
]
325-
)
326345

327346
if len(deco_client_responses) > 0:
328347
# deco_macs is not subscriptable, must be iterated

0 commit comments

Comments
 (0)