mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-02 21:44:31 +02:00
Cleanup interface bandwidth tracking, ref #166
This commit is contained in:
parent
aee405a9f0
commit
4fbd5a4280
2 changed files with 30 additions and 103 deletions
|
@ -434,62 +434,6 @@ class MikrotikAPI:
|
|||
self.lock.release()
|
||||
return True
|
||||
|
||||
# ---------------------------
|
||||
# get_traffic
|
||||
# ---------------------------
|
||||
def get_traffic(self) -> Optional(list):
|
||||
"""Get traffic stats"""
|
||||
if not self.connection_check():
|
||||
return None
|
||||
|
||||
response = self.path("/interface", return_list=False)
|
||||
if response is None:
|
||||
return None
|
||||
|
||||
args = {"stats": True}
|
||||
self.lock.acquire()
|
||||
try:
|
||||
_LOGGER.debug("API query: %s", "/interface/print stats")
|
||||
traffic = response("print", **args)
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
socket_timeout,
|
||||
socket_error,
|
||||
BrokenPipeError,
|
||||
OSError,
|
||||
ValueError,
|
||||
) as api_error:
|
||||
self.disconnect("get_traffic", api_error)
|
||||
self.lock.release()
|
||||
return None
|
||||
except:
|
||||
self.disconnect("get_traffic")
|
||||
self.lock.release()
|
||||
return None
|
||||
|
||||
try:
|
||||
traffic = list(traffic)
|
||||
except librouteros.exceptions.ConnectionClosed as api_error:
|
||||
self.disconnect("get_traffic", api_error)
|
||||
self.lock.release()
|
||||
return None
|
||||
except:
|
||||
self.disconnect("get_traffic")
|
||||
self.lock.release()
|
||||
return None
|
||||
|
||||
self.lock.release()
|
||||
|
||||
return traffic if traffic else None
|
||||
|
||||
# ---------------------------
|
||||
# get_sfp
|
||||
# ---------------------------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue