Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def test_airos():
# Fetch status (large dict, including connected stations)
result = await device.status()
print(f"Result: {result}")
print(f"Result: {result.wireless.mode}")
# Reconnect 'other side'
result = await device.stakick("01:23:45:67:89:AB")
print(f"Result: {result}")
Expand Down
29 changes: 19 additions & 10 deletions airos/airos8.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
from urllib.parse import urlparse

import aiohttp
from mashumaro.exceptions import InvalidFieldValue, MissingField

from .airos8data import AirOSData
from .exceptions import (
ConnectionAuthenticationError,
ConnectionSetupError,
Expand Down Expand Up @@ -185,7 +187,7 @@ async def login(self) -> bool:
logger.exception("Error during login")
raise DeviceConnectionError from err

async def status(self) -> dict:
async def status(self, return_json: bool = False) -> dict | AirOSData:
"""Retrieve status from the device."""
if not self.connected:
logger.error("Not connected, login first")
Expand All @@ -205,15 +207,22 @@ async def status(self) -> dict:
try:
response_text = await 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
try:
airos_data = AirOSData.from_dict(response_json)
except (MissingField, InvalidFieldValue) as err:
logger.exception("Failed to deserialize AirOS data")
raise KeyDataMissingError from err

# Show new enums detected
if airos_data.warnings:
for field_name, messages in airos_data.warnings.items():
for msg in messages:
log = f"AirOS data warning for field '{field_name}': {msg}"
logger.warning(log)

if return_json:
return response_json
return airos_data
except json.JSONDecodeError:
logger.exception(
"JSON Decode Error in authenticated status response"
Expand Down
Loading