Skip to content

Commit d38f3e1

Browse files
committed
formatting
1 parent f45ee6c commit d38f3e1

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ubiquiti/unifi.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,22 @@ def list_clients(self, filters: Dict[str, Union[str, Pattern]]=None, order_by: s
8282

8383
r = self._session.get("{}/api/s/{}/stat/sta".format(self._baseurl, self._site, verify=self._verify_ssl), data="json={}")
8484
self._current_status_code = r.status_code
85-
85+
86+
if self._current_status_code == 401:
87+
raise LoggedInException("Invalid login, or login has expired")
88+
89+
data = r.json()['data']
90+
91+
if filters:
92+
for term, value in filters.items():
93+
value_re = value if isinstance(value, Pattern) else re.compile(value)
94+
95+
data = [x for x in data if term in x.keys() and re.fullmatch(value_re, x[term])]
96+
97+
if order_by:
98+
data = sorted(data, key=lambda x: x[order_by] if order_by in x.keys() else x['_id'])
99+
100+
return data
86101
if self._current_status_code == 401:
87102
raise LoggedInException("Invalid login, or login has expired")
88103

0 commit comments

Comments
 (0)