Skip to content

Commit dc3a337

Browse files
committed
Add critical key data missing exception
1 parent c2749e4 commit dc3a337

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

airos/airos8.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ConnectionSetupError,
1414
DataMissingError,
1515
DeviceConnectionError,
16+
KeyDataMissingError,
1617
)
1718

1819
logger = logging.getLogger(__name__)
@@ -203,7 +204,16 @@ async def status(self) -> dict:
203204
if response.status == 200:
204205
try:
205206
response_text = await response.text()
206-
return json.loads(response_text)
207+
response_json = json.loads(response_text)
208+
if (
209+
"host" not in response_json
210+
or "device_id" not in response_json
211+
):
212+
logger.error(
213+
"Source data missing 'host' or 'device_id' keys"
214+
)
215+
raise KeyDataMissingError from None
216+
return response_json
207217
except json.JSONDecodeError:
208218
logger.exception(
209219
"JSON Decode Error in authenticated status response"

airos/exceptions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,9 @@ class DataMissingError(AirOSException):
1717
"""Raised when expected data is missing."""
1818

1919

20+
class KeyDataMissingError(AirOSException):
21+
"""Raised when return data is missing critical keys."""
22+
23+
2024
class DeviceConnectionError(AirOSException):
2125
"""Raised when unable to connect."""

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.1.0"
7+
version = "0.1.1"
88
license = "MIT"
99
description = "Ubiquity airOS module(s) for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)