Skip to content

Commit

Permalink
improved error handling, updated dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
tofuSCHNITZEL committed Dec 2, 2024
1 parent 8f14722 commit dfc56f2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 2 additions & 2 deletions 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 = "unifi_ap"
version = "0.0.1"
version = "0.0.2"
authors = [
{ name="Tobias Perschon", email="[email protected]" },
]
Expand All @@ -17,7 +17,7 @@ classifiers = [
"Operating System :: OS Independent",
]
dependencies = [
"paramiko==3.3.1",
"paramiko==3.5.0",
]

[project.urls]
Expand Down
13 changes: 11 additions & 2 deletions unifi_ap/unifi_ap.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"""Communicate with an UniFi accesspoint"""

import json
import paramiko
from typing import Any


class UniFiAPConnectionException(Exception):
"""Exception indicating problems with the connection to the accespoint"""

Expand Down Expand Up @@ -68,8 +70,12 @@ def get_ssids(self) -> set | None:
"""Returns all SSIDs from the accesspoint"""
ap_data = self._fetch_ap_data()
ssids: set[str] = set()

if self.unifi_ssid_array not in ap_data:
return None
raise UniFiAPDataException(
"device did not return any vap_table data - is it an accesspoint?"
)

for vap in ap_data[self.unifi_ssid_array]:
ssids.add(vap.get("essid"))

Expand All @@ -81,7 +87,10 @@ def get_clients(self, for_ssids: list | None = None) -> dict | None:
clients: dict[str, dict[str, Any]] = {}

if self.unifi_ssid_array not in ap_data:
return None
raise UniFiAPDataException(
"device did not return any vap_table - is it an accesspoint?"
)

for vap in ap_data[self.unifi_ssid_array]:
if not for_ssids or vap.get("essid") in for_ssids:
client_data = vap.get(self.unifi_client_array)
Expand Down

0 comments on commit dfc56f2

Please sign in to comment.