Python-Unifi-Client 1.1.1__py3-none-any.whl → 1.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,10 +10,6 @@ import http.client as http_client
10
10
  import logging
11
11
  import base64
12
12
 
13
- logging.basicConfig(level=logging.DEBUG)
14
- logging.getLogger('requests.packages.urllib3').setLevel(logging.DEBUG)
15
- http_client.HTTPConnection.debuglevel = 1
16
-
17
13
  # Custom exceptions mirroring PHP equivalents
18
14
  class CurlExtensionNotLoadedException(Exception):
19
15
  def __init__(self):
@@ -109,6 +105,7 @@ class Client:
109
105
  self._last_results_raw = None
110
106
  self._cookies_created_at = 0
111
107
  self._exec_retries = 0
108
+ self.debug = False
112
109
 
113
110
  self._curl_headers = {
114
111
  'Accept': 'application/json',
@@ -198,7 +195,7 @@ class Client:
198
195
  except RequestException as e:
199
196
  raise CurlGeneralErrorException(str(e), None, None)
200
197
 
201
- if self.get_debug:
198
+ if self.debug:
202
199
  print("\n-----------LOGIN-------------")
203
200
  print("GET Options:", get_options)
204
201
  print("POST Options:", post_options)
@@ -259,7 +256,7 @@ class Client:
259
256
  return self.fetch_results(f"/api/s/{self._site}/stat/sysinfo")
260
257
 
261
258
  def get_clients(self):
262
- return self._request(f"/api/s/{self._site}/stat/sta")
259
+ return self.fetch_results(f"/api/s/{self._site}/stat/sta")
263
260
 
264
261
  def block_client(self, mac):
265
262
  return self._request(f"/api/s/{self._site}/cmd/stamgr", method='POST', payload={'cmd': 'block-sta', 'mac': mac})
@@ -751,7 +748,7 @@ class Client:
751
748
  return self.fetch_results(f"/api/s/{self._site}/stat/device", login_required=True, prefix_path=True)
752
749
 
753
750
  def get_device(self, device_id):
754
- return self._request(f"/api/s/{self._site}/stat/device/{device_id}")
751
+ return self.fetch_results(f"/api/s/{self._site}/stat/device/{device_id}")
755
752
 
756
753
  def get_wlan(self, wlan_id: str):
757
754
  """
@@ -928,7 +925,7 @@ class Client:
928
925
  'include_traffic_usage': include_traffic_usage,
929
926
  'include_unifi_devices': include_unifi_devices,
930
927
  })
931
- return self.fetch_results(f"/v2/api/site/{self._site}/clients/active?{query}")
928
+ return self.fetch_results(f"/v2/api/site/{self._site}/clients/active?{query}", prefix_path=True)
932
929
 
933
930
  def list_clients_history(self, only_non_blocked: bool = True, include_unifi_devices: bool = True, within_hours: int = 0):
934
931
  """Fetch offline client device history."""
@@ -1834,7 +1831,7 @@ class Client:
1834
1831
  """Generate a controller backup for the past N days."""
1835
1832
  payload = {'cmd': 'backup', 'days': days}
1836
1833
  result = self.fetch_results(f"/proxy/network/api/s/{self._site}/cmd/backup", payload=payload, prefix_path=False, boolean=False)
1837
- print(f"RAW RESULT FROM FETCH_RESULTS(): {result}")
1834
+ print(f"RAW RESULT FROM FETCH_RESULTS(): {result}") if self.debug else None
1838
1835
  return result
1839
1836
 
1840
1837
  def download_backup(self, filepath: str):
@@ -2330,7 +2327,7 @@ class Client:
2330
2327
  if isinstance(self._last_results_raw, str):
2331
2328
  try:
2332
2329
  response = json.loads(self._last_results_raw)
2333
- print("Fetched response:", response)
2330
+ print("Fetched response:", response) if self.debug else None
2334
2331
  except:
2335
2332
  self._get_json_last_error()
2336
2333
  raise
@@ -2340,8 +2337,8 @@ class Client:
2340
2337
  self._last_error_message = ''
2341
2338
  if 'data' in response:
2342
2339
  if isinstance(response['data'], list):
2343
- print("Response inside fetch_results():", response)
2344
- print("Data:", response.get("data"))
2340
+ print("Response inside fetch_results():", response) if self.debug else None
2341
+ print("Data:", response.get("data")) if self.debug else None
2345
2342
  return response['data'] if not boolean else True
2346
2343
  return [response['data']] if not boolean else True
2347
2344
  return True
@@ -2471,7 +2468,7 @@ class Client:
2471
2468
 
2472
2469
  # 9) handle expired auth
2473
2470
  if http_code == 401:
2474
- if self.get_debug:
2471
+ if self.debug:
2475
2472
  print(f"exec_curl: 401 on {url}, need to re-login")
2476
2473
  if self._exec_retries == 0:
2477
2474
  # clear stored cookie/token
@@ -2485,14 +2482,14 @@ class Client:
2485
2482
  # attempt re-login
2486
2483
  from time import sleep
2487
2484
  if self.login():
2488
- if self.get_debug:
2485
+ if self.debug:
2489
2486
  print("exec_curl: re-login succeeded, retrying exec_curl")
2490
2487
  return self.exec_curl(path, payload, prefix_path)
2491
2488
  raise LoginFailedException('Cookie/Token expired and re-login failed.')
2492
2489
  raise LoginFailedException('Login failed, check credentials.')
2493
2490
 
2494
2491
  # 10) debug dump
2495
- if self.get_debug:
2492
+ if self.debug:
2496
2493
  print("\n---------cURL INFO-----------")
2497
2494
  print("Options:", opts)
2498
2495
  print("URL & PAYLOAD:", url)
@@ -2523,7 +2520,7 @@ class Client:
2523
2520
  }
2524
2521
 
2525
2522
  # Verbose logging if debug
2526
- if self.get_debug:
2523
+ if self.debug:
2527
2524
  # shows per-request wire logs
2528
2525
  logging.getLogger('urllib3').setLevel(logging.DEBUG)
2529
2526
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python_unifi_client
3
- Version: 1.1.1
3
+ Version: 1.1.3
4
4
  Home-page: https://github.com/compdat-llc/unifi-client-python
5
5
  Author: Michael Lapinski
6
6
  Author-email: michaellapinski787@gmail.com
@@ -0,0 +1,6 @@
1
+ python_unifi_client/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
2
+ python_unifi_client/client.py,sha256=PM8O-Xd7Ex8ENWFYQGQEEw6DDHqLYFdHlE_dwGVvgGg,105440
3
+ python_unifi_client-1.1.3.dist-info/METADATA,sha256=kOEMyQpOFbrq0yqM-iNOWuPywsYnsGqM54z8bpTLnVQ,2483
4
+ python_unifi_client-1.1.3.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
5
+ python_unifi_client-1.1.3.dist-info/top_level.txt,sha256=675fDdb69Hi9X8pSEGl6f03ZpUXNiumV-s1B1gXEeYs,20
6
+ python_unifi_client-1.1.3.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- python_unifi_client/__init__.py,sha256=frcCV1k9oG9oKj3dpUqdJg1PxRT2RSN_XKdLCPjaYaY,2
2
- python_unifi_client/client.py,sha256=3pNuIzpj_vJq1fWlhcN5LeD0qhSiGGSsvVd10TZzoUk,105467
3
- python_unifi_client-1.1.1.dist-info/METADATA,sha256=nOF-8Ci1TOBTgvuc4uyPUGB3triP51UgECU_uwQwVlk,2483
4
- python_unifi_client-1.1.1.dist-info/WHEEL,sha256=Nw36Djuh_5VDukK0H78QzOX-_FQEo6V37m3nkm96gtU,91
5
- python_unifi_client-1.1.1.dist-info/top_level.txt,sha256=675fDdb69Hi9X8pSEGl6f03ZpUXNiumV-s1B1gXEeYs,20
6
- python_unifi_client-1.1.1.dist-info/RECORD,,