Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions airos/airos8.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

import aiohttp

from .exceptions import ConnectionFailedError, DataMissingError
from .exceptions import (
ConnectionAuthenticationError,
ConnectionSetupError,
DataMissingError,
DeviceConnectionError,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -93,7 +98,7 @@ async def login(self) -> bool:
) as response:
if not response.cookies:
logger.exception("Empty cookies after login, bailing out.")
raise DataMissingError from None
raise ConnectionSetupError from None
else:
for _, morsel in response.cookies.items():
# If the AIROS_ cookie was parsed but isn't automatically added to the jar, add it manually
Expand Down Expand Up @@ -146,15 +151,15 @@ async def login(self) -> bool:
logger.exception(
"COOKIE JAR IS EMPTY after login POST. This is a major issue."
)
raise DataMissingError from None
raise ConnectionSetupError from None
for cookie in self.session.cookie_jar:
if cookie.key.startswith("AIROS_"):
airos_cookie_found = True
if cookie.key == "ok":
ok_cookie_found = True

if not airos_cookie_found and not ok_cookie_found:
raise DataMissingError from None
raise ConnectionSetupError from None

response_text = await response.text()

Expand All @@ -170,16 +175,16 @@ async def login(self) -> bool:
else:
log = f"Login failed with status {response.status}. Full Response: {response.text}"
logger.error(log)
raise ConnectionFailedError from None
raise ConnectionAuthenticationError from None
except aiohttp.ClientError as err:
logger.exception("Error during login")
raise ConnectionFailedError from err
raise DeviceConnectionError from err

async def status(self) -> dict:
"""Retrieve status from the device."""
if not self.connected:
logger.error("Not connected, login first")
raise ConnectionFailedError from None
raise DeviceConnectionError from None

# --- Step 2: Verify authenticated access by fetching status.cgi ---
authenticated_get_headers = {**self._common_headers}
Expand All @@ -205,4 +210,4 @@ async def status(self) -> dict:
logger.error(log)
except aiohttp.ClientError as err:
logger.exception("Error during authenticated status.cgi call")
raise ConnectionFailedError from err
raise DeviceConnectionError from err
12 changes: 10 additions & 2 deletions airos/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ class AirOSException(Exception):
"""Base error class for this AirOS library."""


class ConnectionFailedError(AirOSException):
"""Raised when unable to connect."""
class ConnectionSetupError(AirOSException):
"""Raised when unable to prepare authentication."""


class ConnectionAuthenticationError(AirOSException):
"""Raised when unable to authenticate."""


class DataMissingError(AirOSException):
"""Raised when expected data is missing."""


class DeviceConnectionError(AirOSException):
"""Raised when unable to connect."""
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "airos"
version = "0.0.7"
version = "0.0.8"
license = "MIT"
description = "Ubiquity airOS module(s) for Python 3."
readme = "README.md"
Expand Down