diff --git a/airos/airos8.py b/airos/airos8.py index e2a6772..e57b73d 100644 --- a/airos/airos8.py +++ b/airos/airos8.py @@ -8,7 +8,12 @@ import aiohttp -from .exceptions import ConnectionFailedError, DataMissingError +from .exceptions import ( + ConnectionAuthenticationError, + ConnectionSetupError, + DataMissingError, + DeviceConnectionError, +) logger = logging.getLogger(__name__) @@ -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 @@ -146,7 +151,7 @@ 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 @@ -154,7 +159,7 @@ async def login(self) -> bool: 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() @@ -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} @@ -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 diff --git a/airos/exceptions.py b/airos/exceptions.py index 408e0f2..e251811 100644 --- a/airos/exceptions.py +++ b/airos/exceptions.py @@ -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.""" diff --git a/pyproject.toml b/pyproject.toml index dddee61..30682c0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"