diff --git a/README.md b/README.md index f3b486d..db61482 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,7 @@ Create a Controller object. - `version` -- the base version of the controller API [v4|v5|unifiOS|UDMP-unifiOS] - `site_id` -- the site ID to access - `ssl_verify` -- Verify the controllers SSL certificate, default=True, can also be False or "path/to/custom_cert.pem" + - `for_hotspot` -- flag that the credentials are for a hotspot operator account ### `block_client(self, mac)` diff --git a/pyunifi/controller.py b/pyunifi/controller.py index aafc9a2..ac48ee5 100644 --- a/pyunifi/controller.py +++ b/pyunifi/controller.py @@ -69,6 +69,7 @@ def __init__( # pylint: disable=r0913 version="v5", site_id="default", ssl_verify=True, + for_hotspot=False, ): """ :param host: the address of the controller host; IP or name @@ -79,6 +80,8 @@ def __init__( # pylint: disable=r0913 :param site_id: the site ID to connect to :param ssl_verify: Verify the controllers SSL certificate, can also be "path/to/custom_cert.pem" + :param for_hotspot: flag that the credentials are for a hotspot + operator account """ self.log = logging.getLogger(__name__ + ".Controller") @@ -91,6 +94,7 @@ def __init__( # pylint: disable=r0913 self.password = password self.site_id = site_id self.ssl_verify = ssl_verify + self.for_hotspot = for_hotspot if version == "unifiOS": self.url = "https://" + host + "/proxy/network/" @@ -182,9 +186,13 @@ def _login(self): self.session = requests.Session() self.session.verify = self.ssl_verify + params = {"username": self.username, "password": self.password} + if self.for_hotspot: + params.update({"for_hotspot": True, "site_name": self.site_id}) + response = self.session.post( self.auth_url, - json={"username": self.username, "password": self.password}, + json=params, headers=self.headers, ) diff --git a/tox.ini b/tox.ini index 25769c5..34eca4a 100644 --- a/tox.ini +++ b/tox.ini @@ -5,7 +5,8 @@ skip_missing_interpreters = True [testenv] setenv = PYTHONPATH = {toxinidir}:{toxinidir}/pyunifi -whitelist_externals = /usr/bin/env +whitelist_externals = /usr/bin/ +allowlist_externals = /usr/bin/env install_command = /usr/bin/env LANG=C.UTF-8 pip install {opts} {packages} commands = py.test --timeout=30 --duration=10 --cov --cov-report= {posargs} @@ -18,4 +19,4 @@ commands = deps = flake8 [flake8] -exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build \ No newline at end of file +exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build