Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
# Ubiquity airOS Module

## Main usage

Via [Home-Assistant](https://www.home-assistant.io) - initial core integration [pending](https://github.com/home-assistant/core/pull/148989).

## Working

Emulating client browser

```example.py
from airos.airos8 import AirOS
import aiohttp
import asyncio

async def test_airos():
session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
device = AirOS(host="192.168.1.2",username="ubnt",password="password",session=session)
# Login
result = await device.login()
print(f"Result: {result}")
# Fetch status (large dict, including connected stations)
result = await device.status()
print(f"Result: {result}")
# Reconnect 'other side'
result = await device.stakick("01:23:45:67:89:AB")
print(f"Result: {result}")

def async_loop(loop: asyncio.AbstractEventLoop) -> int:
return loop.run_until_complete(test_airos())

if __name__ == "__main__":
loop = asyncio.new_event_loop()
result = async_loop(loop)
```
11 changes: 5 additions & 6 deletions airos/airos8.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import json
import logging
from urllib.parse import quote, urlparse
from urllib.parse import urlparse

import aiohttp

Expand Down Expand Up @@ -228,15 +228,11 @@ async def stakick(self, mac_address: str = None) -> bool:
logger.error("Device mac-address missing")
raise DataMissingError from None

# --- Step 2: Verify authenticated access by fetching status.cgi ---
kick_request_headers = {**self._common_headers}
if self.current_csrf_token:
kick_request_headers["X-CSRF-ID"] = self.current_csrf_token

kick_payload = {
"staif": "ath0",
"staid": quote(mac_address.upper(), safe=""),
}
kick_payload = {"staif": "ath0", "staid": mac_address.upper()}

kick_request_headers["Content-Type"] = (
"application/x-www-form-urlencoded; charset=UTF-8"
Expand All @@ -251,6 +247,9 @@ async def stakick(self, mac_address: str = None) -> bool:
) as response:
if response.status == 200:
return True
response_text = await response.text()
log = f"Unable to restart connection response status {response.status} with {response_text}"
logger.error(log)
return False
except (
aiohttp.ClientError,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "airos"
version = "0.0.9"
version = "0.1.0"
license = "MIT"
description = "Ubiquity airOS module(s) for Python 3."
readme = "README.md"
Expand Down