mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-02 05:24:29 +02:00
reverted to official librouteros #9
This commit is contained in:
parent
25e90702d2
commit
3cf637d1ba
9 changed files with 31 additions and 621 deletions
|
@ -2,10 +2,7 @@
|
|||
|
||||
import ssl
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import importlib
|
||||
from threading import Lock
|
||||
from .exceptions import ApiEntryNotFound
|
||||
from .const import (
|
||||
|
@ -13,12 +10,7 @@ from .const import (
|
|||
DEFAULT_ENCODING,
|
||||
)
|
||||
|
||||
MODULE_PATH = os.path.join(os.path.dirname(__file__), "librouteros_custom", "__init__.py")
|
||||
MODULE_NAME = "librouteros_custom"
|
||||
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
|
||||
librouteros_custom = importlib.util.module_from_spec(spec)
|
||||
sys.modules[spec.name] = librouteros_custom
|
||||
spec.loader.exec_module(librouteros_custom)
|
||||
import librouteros
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
@ -84,13 +76,13 @@ class MikrotikAPI:
|
|||
kwargs["ssl_wrapper"] = self._ssl_wrapper
|
||||
self.lock.acquire()
|
||||
try:
|
||||
self._connection = librouteros_custom.connect(self._host, self._username, self._password, **kwargs)
|
||||
self._connection = librouteros.connect(self._host, self._username, self._password, **kwargs)
|
||||
except (
|
||||
librouteros_custom.exceptions.TrapError,
|
||||
librouteros_custom.exceptions.MultiTrapError,
|
||||
librouteros_custom.exceptions.ConnectionClosed,
|
||||
librouteros_custom.exceptions.ProtocolError,
|
||||
librouteros_custom.exceptions.FatalError,
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ConnectionClosed,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
BrokenPipeError,
|
||||
OSError
|
||||
|
@ -147,16 +139,16 @@ class MikrotikAPI:
|
|||
try:
|
||||
response = self._connection.path(path)
|
||||
_LOGGER.debug("API response (%s): %s", path, response)
|
||||
except librouteros_custom.exceptions.ConnectionClosed:
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
return None
|
||||
except (
|
||||
librouteros_custom.exceptions.TrapError,
|
||||
librouteros_custom.exceptions.MultiTrapError,
|
||||
librouteros_custom.exceptions.ProtocolError,
|
||||
librouteros_custom.exceptions.FatalError,
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
BrokenPipeError,
|
||||
OSError,
|
||||
|
@ -174,7 +166,7 @@ class MikrotikAPI:
|
|||
|
||||
try:
|
||||
tuple(response)
|
||||
except librouteros_custom.exceptions.ConnectionClosed as api_error:
|
||||
except librouteros.exceptions.ConnectionClosed as api_error:
|
||||
_LOGGER.error("Mikrotik %s error while path %s", self._host, api_error)
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
|
@ -221,16 +213,16 @@ class MikrotikAPI:
|
|||
self.lock.acquire()
|
||||
try:
|
||||
response.update(**params)
|
||||
except librouteros_custom.exceptions.ConnectionClosed:
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
return False
|
||||
except (
|
||||
librouteros_custom.exceptions.TrapError,
|
||||
librouteros_custom.exceptions.MultiTrapError,
|
||||
librouteros_custom.exceptions.ProtocolError,
|
||||
librouteros_custom.exceptions.FatalError,
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
BrokenPipeError,
|
||||
OSError,
|
||||
|
@ -282,16 +274,16 @@ class MikrotikAPI:
|
|||
try:
|
||||
run = response('run', **{'.id': tmp['.id']})
|
||||
tuple(run)
|
||||
except librouteros_custom.exceptions.ConnectionClosed:
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
return False
|
||||
except (
|
||||
librouteros_custom.exceptions.TrapError,
|
||||
librouteros_custom.exceptions.MultiTrapError,
|
||||
librouteros_custom.exceptions.ProtocolError,
|
||||
librouteros_custom.exceptions.FatalError,
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
BrokenPipeError,
|
||||
OSError,
|
||||
|
@ -336,16 +328,16 @@ class MikrotikAPI:
|
|||
try:
|
||||
traffic = response('monitor-traffic', **args)
|
||||
_LOGGER.debug("API response (%s): %s", "/interface/monitor-traffic", traffic)
|
||||
except librouteros_custom.exceptions.ConnectionClosed:
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self.disconnect()
|
||||
self.lock.release()
|
||||
return None
|
||||
except (
|
||||
librouteros_custom.exceptions.TrapError,
|
||||
librouteros_custom.exceptions.MultiTrapError,
|
||||
librouteros_custom.exceptions.ProtocolError,
|
||||
librouteros_custom.exceptions.FatalError,
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError,
|
||||
ssl.SSLError,
|
||||
BrokenPipeError,
|
||||
OSError,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue