Skip to content

Commit 65d84ac

Browse files
committed
Bump json to mashumaro
1 parent a007228 commit 65d84ac

File tree

7 files changed

+436
-12
lines changed

7 files changed

+436
-12
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ async def test_airos():
2222
# Fetch status (large dict, including connected stations)
2323
result = await device.status()
2424
print(f"Result: {result}")
25+
print(f"Result: {result.wireless.mode}")
2526
# Reconnect 'other side'
2627
result = await device.stakick("01:23:45:67:89:AB")
2728
print(f"Result: {result}")

airos/airos8.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
from urllib.parse import urlparse
88

99
import aiohttp
10+
from mashumaro.exceptions import InvalidFieldValue, MissingField
1011

12+
from .airos8data import AirOSData
1113
from .exceptions import (
1214
ConnectionAuthenticationError,
1315
ConnectionSetupError,
@@ -185,7 +187,7 @@ async def login(self) -> bool:
185187
logger.exception("Error during login")
186188
raise DeviceConnectionError from err
187189

188-
async def status(self) -> dict:
190+
async def status(self, return_json: bool = False) -> dict:
189191
"""Retrieve status from the device."""
190192
if not self.connected:
191193
logger.error("Not connected, login first")
@@ -205,15 +207,24 @@ async def status(self) -> dict:
205207
try:
206208
response_text = await response.text()
207209
response_json = json.loads(response_text)
208-
if (
209-
"host" not in response_json
210-
or "device_id" not in response_json["host"]
211-
):
212-
logger.error(
210+
try:
211+
airos_data = AirOSData.from_dict(response_json)
212+
except (MissingField, InvalidFieldValue) as err:
213+
logger.exception(
213214
"Source data missing 'host' or 'device_id' keys"
214215
)
215-
raise KeyDataMissingError from None
216-
return response_json
216+
raise KeyDataMissingError from err
217+
218+
# Show new enums detected
219+
if airos_data.warnings:
220+
for field_name, messages in airos_data.warnings.items():
221+
for msg in messages:
222+
log = f"AirOS data warning for field '{field_name}': {msg}"
223+
logger.warning(log)
224+
225+
if return_json:
226+
return response_json
227+
return airos_data
217228
except json.JSONDecodeError:
218229
logger.exception(
219230
"JSON Decode Error in authenticated status response"

0 commit comments

Comments
 (0)