Skip to content

Commit 0658427

Browse files
committed
Add more logging
1 parent b7fb058 commit 0658427

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

airos/base.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ def _get_authenticated_headers(
206206
headers["X-CSRF-ID"] = self._csrf_id
207207

208208
if self._auth_cookie: # pragma: no cover
209+
_LOGGER.error("TESTv6 - auth_cookie found: AIROS_%s", self._auth_cookie)
209210
headers["Cookie"] = f"AIROS_{self._auth_cookie}"
210211

211212
return headers
@@ -219,6 +220,7 @@ def _store_auth_data(self, response: aiohttp.ClientResponse) -> None:
219220
for set_cookie in response.headers.getall("Set-Cookie", []):
220221
cookie.load(set_cookie)
221222
for key, morsel in cookie.items():
223+
_LOGGER.error("TESTv6 - cookie handling: %s with %s", key, morsel.value)
222224
if key.startswith("AIROS_"):
223225
self._auth_cookie = morsel.key[6:] + "=" + morsel.value
224226
break
@@ -261,6 +263,7 @@ async def _request_json(
261263
data=form_data,
262264
headers=request_headers, # Pass the constructed headers
263265
) as response:
266+
_LOGGER.error("TESTv6 - Response code: %s", response.status)
264267
response.raise_for_status()
265268
response_text = await response.text()
266269
_LOGGER.debug("Successfully fetched JSON from %s", url)
@@ -310,8 +313,10 @@ async def login(self) -> None:
310313
_LOGGER.error("TESTv6 - gives URL not found, trying alternative v6 URL")
311314
# Try next URL
312315
except AirOSConnectionSetupError as err:
316+
_LOGGER.error("TESTv6 - failed to login to v8 URL")
313317
raise AirOSConnectionSetupError("Failed to login to AirOS device") from err
314318
else:
319+
_LOGGER.error("TESTv6 - returning from v8 login")
315320
return
316321

317322
# Start of v6, go for cookies
@@ -357,6 +362,7 @@ async def login(self) -> None:
357362
"Referer": self._login_urls["v6_login_cgi"],
358363
}
359364

365+
_LOGGER.error("TESTv6 - start v6 attempts")
360366
for url_to_try in v6_urls_to_try:
361367
# --- ATTEMPT A: Simple Payload (form-urlencoded) ---
362368
try:
@@ -373,15 +379,17 @@ async def login(self) -> None:
373379
ct_form=True,
374380
)
375381
except (AirOSUrlNotFoundError, AirOSConnectionSetupError) as err:
376-
_LOGGER.warning(
382+
_LOGGER.error(
377383
"TESTv6 - V6 simple form-urlencoded failed (%s) on %s. Error: %s",
378384
type(err).__name__,
379385
url_to_try,
380386
err,
381387
)
382388
except AirOSConnectionAuthenticationError:
389+
_LOGGER.error("TESTv6 - autherror during simple form-urlencoded")
383390
raise
384391
else:
392+
_LOGGER.error("TESTv6 - returning from simple form-urlencoded")
385393
return # Success
386394

387395
# --- ATTEMPT B: Simple Payload (multipart/form-data) ---
@@ -398,15 +406,17 @@ async def login(self) -> None:
398406
authenticated=True,
399407
)
400408
except (AirOSUrlNotFoundError, AirOSConnectionSetupError) as err:
401-
_LOGGER.warning(
409+
_LOGGER.error(
402410
"TESTv6 - V6 simple multipart failed (%s) on %s. Error: %s",
403411
type(err).__name__,
404412
url_to_try,
405413
err,
406414
)
407415
except AirOSConnectionAuthenticationError:
416+
_LOGGER.error("TESTv6 - autherror during extended multipart")
408417
raise
409418
else:
419+
_LOGGER.error("TESTv6 - returning from simple multipart")
410420
return # Success
411421

412422
# --- ATTEMPT C: Extended Payload (form-urlencoded) ---
@@ -424,15 +434,17 @@ async def login(self) -> None:
424434
ct_form=True,
425435
)
426436
except (AirOSUrlNotFoundError, AirOSConnectionSetupError) as err:
427-
_LOGGER.warning(
437+
_LOGGER.error(
428438
"TESTv6 - V6 extended form-urlencoded failed (%s) on %s. Error: %s",
429439
type(err).__name__,
430440
url_to_try,
431441
err,
432442
)
433443
except AirOSConnectionAuthenticationError:
444+
_LOGGER.error("TESTv6 - autherror during extended form-urlencoded")
434445
raise
435446
else:
447+
_LOGGER.error("TESTv6 - returning from extended form-urlencoded")
436448
return # Success
437449

438450
# --- ATTEMPT D: Extended Payload (multipart/form-data) ---
@@ -449,14 +461,16 @@ async def login(self) -> None:
449461
authenticated=True,
450462
)
451463
except (AirOSUrlNotFoundError, AirOSConnectionSetupError) as err:
452-
_LOGGER.warning(
464+
_LOGGER.error(
453465
"TESTv6 - V6 extended multipart failed (%s) on %s. Trying next URL.",
454466
type(err).__name__,
455467
url_to_try,
456468
)
457469
except AirOSConnectionAuthenticationError:
470+
_LOGGER.error("TESTv6 - autherror during extended multipart")
458471
raise
459472
else:
473+
_LOGGER.error("TESTv6 - returning from extended multipart")
460474
return # Success
461475

462476
# If the loop finishes without returning, login failed for all combinations

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "airos"
7-
version = "0.5.7a4"
7+
version = "0.5.7a5"
88
license = "MIT"
99
description = "Ubiquiti airOS module(s) for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)