From dfc56f2713e8253a8922eefc3c29b3546c4ab764 Mon Sep 17 00:00:00 2001 From: Tobias Perschon Date: Mon, 2 Dec 2024 23:56:42 +0100 Subject: [PATCH] improved error handling, updated dependency --- pyproject.toml | 4 ++-- unifi_ap/unifi_ap.py | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 27c3272..4393b88 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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="tobias@perschon.at" }, ] @@ -17,7 +17,7 @@ classifiers = [ "Operating System :: OS Independent", ] dependencies = [ - "paramiko==3.3.1", + "paramiko==3.5.0", ] [project.urls] diff --git a/unifi_ap/unifi_ap.py b/unifi_ap/unifi_ap.py index fa2865d..ee0f26f 100644 --- a/unifi_ap/unifi_ap.py +++ b/unifi_ap/unifi_ap.py @@ -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""" @@ -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")) @@ -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)