From dc3a337dbff92cbb6d623b66baf4139b2956c57e Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 21 Jul 2025 20:58:39 +0200 Subject: [PATCH 1/2] Add critical key data missing exception --- airos/airos8.py | 12 +++++++++++- airos/exceptions.py | 4 ++++ pyproject.toml | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/airos/airos8.py b/airos/airos8.py index d69b677..401055d 100644 --- a/airos/airos8.py +++ b/airos/airos8.py @@ -13,6 +13,7 @@ ConnectionSetupError, DataMissingError, DeviceConnectionError, + KeyDataMissingError, ) logger = logging.getLogger(__name__) @@ -203,7 +204,16 @@ async def status(self) -> dict: if response.status == 200: try: response_text = await response.text() - return json.loads(response_text) + response_json = json.loads(response_text) + if ( + "host" not in response_json + or "device_id" not in response_json + ): + logger.error( + "Source data missing 'host' or 'device_id' keys" + ) + raise KeyDataMissingError from None + return response_json except json.JSONDecodeError: logger.exception( "JSON Decode Error in authenticated status response" diff --git a/airos/exceptions.py b/airos/exceptions.py index e251811..ffcc3b8 100644 --- a/airos/exceptions.py +++ b/airos/exceptions.py @@ -17,5 +17,9 @@ class DataMissingError(AirOSException): """Raised when expected data is missing.""" +class KeyDataMissingError(AirOSException): + """Raised when return data is missing critical keys.""" + + class DeviceConnectionError(AirOSException): """Raised when unable to connect.""" diff --git a/pyproject.toml b/pyproject.toml index 7c2ac17..ea3754b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "airos" -version = "0.1.0" +version = "0.1.1" license = "MIT" description = "Ubiquity airOS module(s) for Python 3." readme = "README.md" From a00722871927b9a1c6960e592441ca0c622465b5 Mon Sep 17 00:00:00 2001 From: Tom Scholten Date: Mon, 21 Jul 2025 21:04:54 +0200 Subject: [PATCH 2/2] Fix test --- airos/airos8.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/airos/airos8.py b/airos/airos8.py index 401055d..a7461b4 100644 --- a/airos/airos8.py +++ b/airos/airos8.py @@ -207,7 +207,7 @@ async def status(self) -> dict: response_json = json.loads(response_text) if ( "host" not in response_json - or "device_id" not in response_json + or "device_id" not in response_json["host"] ): logger.error( "Source data missing 'host' or 'device_id' keys"