Skip to content

Commit abae629

Browse files
authored
Merge pull request #19 from CoMPaTech/testing
Functional stakick progress, version bump a0
2 parents f1ec171 + c2749e4 commit abae629

File tree

3 files changed

+40
-7
lines changed

3 files changed

+40
-7
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
11
# Ubiquity airOS Module
2+
3+
## Main usage
4+
5+
Via [Home-Assistant](https://www.home-assistant.io) - initial core integration [pending](https://github.com/home-assistant/core/pull/148989).
6+
7+
## Working
8+
9+
Emulating client browser
10+
11+
```example.py
12+
from airos.airos8 import AirOS
13+
import aiohttp
14+
import asyncio
15+
16+
async def test_airos():
17+
session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
18+
device = AirOS(host="192.168.1.2",username="ubnt",password="password",session=session)
19+
# Login
20+
result = await device.login()
21+
print(f"Result: {result}")
22+
# Fetch status (large dict, including connected stations)
23+
result = await device.status()
24+
print(f"Result: {result}")
25+
# Reconnect 'other side'
26+
result = await device.stakick("01:23:45:67:89:AB")
27+
print(f"Result: {result}")
28+
29+
def async_loop(loop: asyncio.AbstractEventLoop) -> int:
30+
return loop.run_until_complete(test_airos())
31+
32+
if __name__ == "__main__":
33+
loop = asyncio.new_event_loop()
34+
result = async_loop(loop)
35+
```

airos/airos8.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import json
66
import logging
7-
from urllib.parse import quote, urlparse
7+
from urllib.parse import urlparse
88

99
import aiohttp
1010

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

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

236-
kick_payload = {
237-
"staif": "ath0",
238-
"staid": quote(mac_address.upper(), safe=""),
239-
}
235+
kick_payload = {"staif": "ath0", "staid": mac_address.upper()}
240236

241237
kick_request_headers["Content-Type"] = (
242238
"application/x-www-form-urlencoded; charset=UTF-8"
@@ -251,6 +247,9 @@ async def stakick(self, mac_address: str = None) -> bool:
251247
) as response:
252248
if response.status == 200:
253249
return True
250+
response_text = await response.text()
251+
log = f"Unable to restart connection response status {response.status} with {response_text}"
252+
logger.error(log)
254253
return False
255254
except (
256255
aiohttp.ClientError,

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "airos"
7-
version = "0.0.9"
7+
version = "0.1.0"
88
license = "MIT"
99
description = "Ubiquity airOS module(s) for Python 3."
1010
readme = "README.md"

0 commit comments

Comments
 (0)