Skip to content
Open
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)`

Expand Down
10 changes: 9 additions & 1 deletion pyunifi/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand All @@ -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/"
Expand Down Expand Up @@ -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,
)

Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -18,4 +19,4 @@ commands =
deps = flake8

[flake8]
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build