diff --git a/README.md b/README.md index 43cf59e..dedd61b 100644 --- a/README.md +++ b/README.md @@ -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) +``` diff --git a/airos/airos8.py b/airos/airos8.py index 7eaa82b..d69b677 100644 --- a/airos/airos8.py +++ b/airos/airos8.py @@ -4,7 +4,7 @@ import json import logging -from urllib.parse import quote, urlparse +from urllib.parse import urlparse import aiohttp @@ -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" @@ -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, diff --git a/pyproject.toml b/pyproject.toml index 699af56..7c2ac17 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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"