77from urllib .parse import urlparse
88
99import aiohttp
10+ from mashumaro .exceptions import InvalidFieldValue , MissingField
1011
12+ from .airos8data import AirOSData
1113from .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 | AirOSData :
189191 """Retrieve status from the device."""
190192 if not self .connected :
191193 logger .error ("Not connected, login first" )
@@ -205,15 +207,22 @@ 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 (
213- "Source data missing 'host' or 'device_id' keys"
214- )
215- raise KeyDataMissingError from None
216- return response_json
210+ try :
211+ airos_data = AirOSData .from_dict (response_json )
212+ except (MissingField , InvalidFieldValue ) as err :
213+ logger .exception ("Failed to deserialize AirOS data" )
214+ raise KeyDataMissingError from err
215+
216+ # Show new enums detected
217+ if airos_data .warnings :
218+ for field_name , messages in airos_data .warnings .items ():
219+ for msg in messages :
220+ log = f"AirOS data warning for field '{ field_name } ': { msg } "
221+ logger .warning (log )
222+
223+ if return_json :
224+ return response_json
225+ return airos_data
217226 except json .JSONDecodeError :
218227 logger .exception (
219228 "JSON Decode Error in authenticated status response"
0 commit comments