@@ -59,7 +59,9 @@ Here is a more detailed example of how to use the library to connect, fetch stat
5959``` Python
6060import aiohttp
6161import asyncio
62- from airos.airos8 import AirOS
62+ from airos.airos6 import AirOS6, AirOS6Data
63+ from airos.airos8 import AirOS8, AirOS8Data
64+ from airos.helpers import DetectDeviceData, async_get_firmware_data
6365
6466async def main ():
6567 """ Main function to demonstrate library usage."""
@@ -68,30 +70,41 @@ async def main():
6870 # but not recommended for production environments without proper validation.
6971 session = aiohttp.ClientSession(connector = aiohttp.TCPConnector(verify_ssl = False ))
7072
73+ # Connection data
74+ conn_data = {
75+ " host" : " 192.168.1.2" ,
76+ " username" : " ubnt" ,
77+ " password" : " password" ,
78+ " session" : session
79+ }
80+
81+ device_data: DetectDeviceData = await async_get_firmware_data(** conn_data)
82+ airos_class: type[AirOS8 | AirOS6] = AirOS8
83+ AirOSDataDetect = AirOS8Data | AirOS6Data
84+
85+ if device_data[" fw_major" ] == 6 :
86+ airos_class = AirOS6
87+
7188 # Initialize the AirOS device object.
72- device = AirOS(
73- host = " 192.168.1.2" ,
74- username = " ubnt" ,
75- password = " password" ,
76- session = session
77- )
89+ airos_device = airos_class(** conn_data)
90+
7891
7992 try :
8093 # Step 1: Login to the device.
81- login_result = await device .login()
94+ login_result = await airos_device .login()
8295 print (f " Login successful: { login_result} " )
8396
8497 # Step 2: Fetch the device status.
85- status_data = await device .status()
98+ status_data = await airos_device .status()
8699 print (" \n --- Device Status ---" )
87100 print (f " Device Name: { status_data.host.hostname} " )
88101 print (f " Wireless Mode: { status_data.wireless.mode} " )
89102 print (f " Firmware Version: { status_data.host.fwversion} " )
90103
91104 # Fetch and display connected stations if available
92- if status_data.wireless.stations :
105+ if status_data.wireless.sta :
93106 print (" \n --- Connected Stations ---" )
94- for station in status_data.wireless.stations :
107+ for station in status_data.wireless.sta :
95108 print (f " - MAC: { station.mac} " )
96109 print (f " Signal: { station.signal} dBm " )
97110 print (f " Uptime: { station.uptime} seconds " )
0 commit comments