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 :
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