1111import aiohttp
1212from mashumaro .exceptions import InvalidFieldValue , MissingField
1313
14- from .data import AirOS8Data as AirOSData , redact_data_smart
14+ from .data import (
15+ AirOS8Data as AirOSData ,
16+ DerivedWirelessMode ,
17+ DerivedWirelessRole ,
18+ redact_data_smart ,
19+ )
1520from .exceptions import (
1621 AirOSConnectionAuthenticationError ,
1722 AirOSConnectionSetupError ,
@@ -54,6 +59,8 @@ def __init__(
5459 self ._status_cgi_url = f"{ self .base_url } /status.cgi" # AirOS 8
5560 self ._stakick_cgi_url = f"{ self .base_url } /stakick.cgi" # AirOS 8
5661 self ._provmode_url = f"{ self .base_url } /api/provmode" # AirOS 8
62+ self ._warnings_url = f"{ self .base_url } /api/warnings" # AirOS 8
63+ self ._update_check_url = f"{ self .base_url } /api/fw/update-check" # AirOS 8
5764 self .current_csrf_token : str | None = None
5865
5966 self ._use_json_for_login_post = False
@@ -201,6 +208,8 @@ def derived_data(response: dict[str, Any]) -> dict[str, Any]:
201208 "access_point" : False ,
202209 "ptp" : False ,
203210 "ptmp" : False ,
211+ "role" : DerivedWirelessRole .STATION ,
212+ "mode" : DerivedWirelessMode .PTP ,
204213 }
205214
206215 # Access Point / Station vs PTP/PtMP
@@ -209,12 +218,16 @@ def derived_data(response: dict[str, Any]) -> dict[str, Any]:
209218 case "ap-ptmp" :
210219 derived ["access_point" ] = True
211220 derived ["ptmp" ] = True
221+ derived ["role" ] = DerivedWirelessRole .ACCESS_POINT
222+ derived ["mode" ] = DerivedWirelessMode .PTMP
212223 case "sta-ptmp" :
213224 derived ["station" ] = True
214225 derived ["ptmp" ] = True
226+ derived ["mode" ] = DerivedWirelessMode .PTMP
215227 case "ap-ptp" :
216228 derived ["access_point" ] = True
217229 derived ["ptp" ] = True
230+ derived ["role" ] = DerivedWirelessRole .ACCESS_POINT
218231 case "sta-ptp" :
219232 derived ["station" ] = True
220233 derived ["ptp" ] = True
@@ -384,3 +397,69 @@ async def provmode(self, active: bool = False) -> bool:
384397 except asyncio .CancelledError :
385398 _LOGGER .info ("Provisioning mode change task was cancelled" )
386399 raise
400+
401+ async def warnings (self ) -> dict [str , Any ] | Any :
402+ """Get warnings."""
403+ if not self .connected :
404+ _LOGGER .error ("Not connected, login first" )
405+ raise AirOSDeviceConnectionError from None
406+
407+ request_headers = {** self ._common_headers }
408+ if self .current_csrf_token :
409+ request_headers ["X-CSRF-ID" ] = self .current_csrf_token
410+
411+ # Formal call is '/api/warnings?_=1755249683586'
412+ try :
413+ async with self .session .get (
414+ self ._warnings_url ,
415+ headers = request_headers ,
416+ ) as response :
417+ response_text = await response .text ()
418+ if response .status == 200 :
419+ return json .loads (response_text )
420+ log = f"Unable to fech warning status { response .status } with { response_text } "
421+ _LOGGER .error (log )
422+ raise AirOSDataMissingError from None
423+ except json .JSONDecodeError :
424+ _LOGGER .exception ("JSON Decode Error in warning response" )
425+ raise AirOSDataMissingError from None
426+ except (TimeoutError , aiohttp .ClientError ) as err :
427+ _LOGGER .exception ("Error during call to retrieve warnings: %s" , err )
428+ raise AirOSDeviceConnectionError from err
429+ except asyncio .CancelledError :
430+ _LOGGER .info ("Warning check task was cancelled" )
431+ raise
432+
433+ async def update_check (self ) -> dict [str , Any ] | Any :
434+ """Get warnings."""
435+ if not self .connected :
436+ _LOGGER .error ("Not connected, login first" )
437+ raise AirOSDeviceConnectionError from None
438+
439+ request_headers = {** self ._common_headers }
440+ if self .current_csrf_token :
441+ request_headers ["X-CSRF-ID" ] = self .current_csrf_token
442+ request_headers ["Content-type" ] = "application/json"
443+
444+ # Post without data
445+ try :
446+ async with self .session .post (
447+ self ._update_check_url ,
448+ headers = request_headers ,
449+ json = {},
450+ ) as response :
451+ response_text = await response .text ()
452+ if response .status == 200 :
453+ return json .loads (response_text )
454+ log = f"Unable to fech update status { response .status } with { response_text } "
455+ _LOGGER .error (log )
456+ raise AirOSDataMissingError from None
457+ except json .JSONDecodeError :
458+ _LOGGER .exception ("JSON Decode Error in warning response" )
459+ raise AirOSDataMissingError from None
460+ except (TimeoutError , aiohttp .ClientError ) as err :
461+ _LOGGER .exception ("Error during call to retrieve update status: %s" , err )
462+ raise AirOSDeviceConnectionError from err
463+ except asyncio .CancelledError :
464+ _LOGGER .info ("Warning update status task was cancelled" )
465+ raise
0 commit comments