diff --git a/airos/airos8.py b/airos/airos8.py index d69b677..a7461b4 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["host"] + ): + 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"