diff --git a/app/omada.py b/app/omada.py index 99fb325..7f1254d 100644 --- a/app/omada.py +++ b/app/omada.py @@ -103,9 +103,12 @@ class OmadaClient: resp.raise_for_status() data = resp.json() if data.get("errorCode", 0) in (-1006, -1003, -30109): + logger.info("Session error %s — re-authenticating", data.get("errorCode")) self._token = None self._sites = None await self._login() + await self._fetch_sites() + client = self._get_client() resp = await client.request(method, url, headers=self._auth_headers(), **kwargs) resp.raise_for_status() data = resp.json() @@ -160,6 +163,8 @@ class OmadaClient: """Fetch APs from every accessible site and return a combined list.""" await self._ensure_ready() all_aps = [] + failed_sites = 0 + total_sites = len(self._sites) for site_name, site_key in self._sites.items(): try: data = await self._request_with_retry( @@ -174,7 +179,15 @@ class OmadaClient: all_aps.append(d) except Exception as exc: logger.warning("Failed to fetch devices for site '%s': %s", site_name, exc) - logger.info("Fetched %d APs across %d sites", len(all_aps), len(self._sites)) + failed_sites += 1 + if failed_sites > 0 and failed_sites == total_sites: + # Every site failed — session is likely stale with an unrecognised error code. + # Clear auth state so the next request triggers a full re-login instead of + # requiring a container restart. + logger.warning("All %d site(s) failed — clearing session state to force re-auth on next request", total_sites) + self._token = None + self._sites = None + logger.info("Fetched %d APs across %d sites", len(all_aps), total_sites) return all_aps async def _get_ap_uptime(self, mac: str, site_key: str) -> int: