| 1 |
"""Ubiquiti AirOS 6.""" |
| 2 |
|
| 3 |
from __future__ import annotations |
| 4 |
|
| 5 |
import logging |
| 6 |
from typing import Any |
| 7 |
|
| 8 |
import aiohttp |
| 9 |
|
| 10 |
from .base import AirOS |
| 11 |
from .data import AirOS6Data, DerivedWirelessRole |
| 12 |
from .exceptions import AirOSDeviceConnectionError, AirOSNotSupportedError |
| 13 |
|
| 14 |
_LOGGER = logging.getLogger(__name__) |
| 15 |
|
| 16 |
|
| 17 |
class AirOS6(AirOS[AirOS6Data]): |
| 18 |
"""AirOS 6 connection class.""" |
| 19 |
|
| 20 |
def __init__( |
| 21 |
self, |
| 22 |
host: str, |
| 23 |
username: str, |
| 24 |
password: str, |
| 25 |
session: aiohttp.ClientSession, |
| 26 |
use_ssl: bool = True, |
| 27 |
) -> None: |
| 28 |
"""Initialize AirOS8 class.""" |
| 29 |
super().__init__( |
| 30 |
data_model=AirOS6Data, |
| 31 |
host=host, |
| 32 |
username=username, |
| 33 |
password=password, |
| 34 |
session=session, |
| 35 |
use_ssl=use_ssl, |
| 36 |
) |
| 37 |
|
| 38 |
@staticmethod |
| 39 |
def _derived_wireless_data( |
| 40 |
derived: dict[str, Any], response: dict[str, Any] |
| 41 |
) -> dict[str, Any]: |
| 42 |
"""Add derived wireless data to the device response.""" |
| 43 |
# Access Point / Station - no info on ptp/ptmp |
| 44 |
# assuming ptp for station mode |
| 45 |
derived["ptp"] = True |
| 46 |
wireless_mode = response.get("wireless", {}).get("mode", "") |
| 47 |
match wireless_mode: |
| 48 |
case "ap": |
| 49 |
derived["access_point"] = True |
| 50 |
derived["role"] = DerivedWirelessRole.ACCESS_POINT |
| 51 |
case "sta": |
| 52 |
derived["station"] = True |
| 53 |
|
| 54 |
return derived |
| 55 |
|
| 56 |
async def login(self) -> None: |
| 57 |
"""Login to airOS v6 devices.""" |
| 58 |
try: |
| 59 |
await self._login_v6() |
| 60 |
except (TimeoutError, aiohttp.ClientError) as err: |
| 61 |
_LOGGER.exception("Error occurred connecting to the airOS device") |
| 62 |
raise AirOSDeviceConnectionError from err |
| 63 |
|
| 64 |
async def update_check(self, force: bool = False) -> dict[str, Any]: |
| 65 |
"""Check for firmware updates. Not supported on AirOS6.""" |
| 66 |
raise AirOSNotSupportedError("Firmware update check not supported on AirOS6.") |
| 67 |
|
| 68 |
async def stakick(self, mac_address: str | None = None) -> bool: |
| 69 |
"""Kick a station off the AP. Not supported on AirOS6.""" |
| 70 |
raise AirOSNotSupportedError("Station kick not supported on AirOS6.") |
| 71 |
|
| 72 |
async def provmode(self, active: bool = False) -> bool: |
| 73 |
"""Enable/Disable provisioning mode. Not supported on AirOS6.""" |
| 74 |
raise AirOSNotSupportedError("Provisioning mode not supported on AirOS6.") |
| 75 |
|
| 76 |
async def warnings(self) -> dict[str, Any]: |
| 77 |
"""Get device warnings. Not supported on AirOS6.""" |
| 78 |
raise AirOSNotSupportedError("Device warnings not supported on AirOS6.") |
| 79 |
|
| 80 |
async def progress(self) -> dict[str, Any]: |
| 81 |
"""Get firmware progress. Not supported on AirOS6.""" |
| 82 |
raise AirOSNotSupportedError("Firmware progress not supported on AirOS6.") |
| 83 |
|
| 84 |
async def download(self) -> dict[str, Any]: |
| 85 |
"""Download the device firmware. Not supported on AirOS6.""" |
| 86 |
raise AirOSNotSupportedError("Firmware download not supported on AirOS6.") |
| 87 |
|
| 88 |
async def install(self) -> dict[str, Any]: |
| 89 |
"""Install a firmware update. Not supported on AirOS6.""" |
| 90 |
raise AirOSNotSupportedError("Firmware install not supported on AirOS6.") |