mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-26 02:38:47 +02:00
changed librouteros library name to avoid conflict with loaded library #2
This commit is contained in:
parent
10898768e3
commit
0896d0c991
8 changed files with 42 additions and 42 deletions
|
@ -3,17 +3,17 @@
|
||||||
from socket import create_connection
|
from socket import create_connection
|
||||||
from collections import ChainMap
|
from collections import ChainMap
|
||||||
|
|
||||||
from librouteros.exceptions import (
|
from .exceptions import (
|
||||||
ConnectionClosed,
|
ConnectionClosed,
|
||||||
FatalError,
|
FatalError,
|
||||||
)
|
)
|
||||||
from librouteros.connections import SocketTransport
|
from .connections import SocketTransport
|
||||||
from librouteros.protocol import ApiProtocol
|
from .protocol import ApiProtocol
|
||||||
from librouteros.login import (
|
from .login import (
|
||||||
plain,
|
plain,
|
||||||
token,
|
token,
|
||||||
)
|
)
|
||||||
from librouteros.api import Api
|
from .api import Api
|
||||||
|
|
||||||
DEFAULTS = {
|
DEFAULTS = {
|
||||||
'timeout': 10,
|
'timeout': 10,
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
from posixpath import join as pjoin
|
from posixpath import join as pjoin
|
||||||
|
|
||||||
from librouteros.exceptions import TrapError, MultiTrapError
|
from .exceptions import TrapError, MultiTrapError
|
||||||
from librouteros.protocol import (
|
from .protocol import (
|
||||||
compose_word,
|
compose_word,
|
||||||
parse_word,
|
parse_word,
|
||||||
)
|
)
|
||||||
from librouteros.query import Query
|
from .query import Query
|
||||||
|
|
||||||
|
|
||||||
class Api:
|
class Api:
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
|
|
||||||
from librouteros.exceptions import ConnectionClosed
|
from .exceptions import ConnectionClosed
|
||||||
|
|
||||||
|
|
||||||
class SocketTransport:
|
class SocketTransport:
|
|
@ -3,7 +3,7 @@
|
||||||
from struct import pack, unpack
|
from struct import pack, unpack
|
||||||
from logging import getLogger, NullHandler
|
from logging import getLogger, NullHandler
|
||||||
|
|
||||||
from librouteros.exceptions import (
|
from .exceptions import (
|
||||||
ProtocolError,
|
ProtocolError,
|
||||||
FatalError,
|
FatalError,
|
||||||
)
|
)
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: UTF-8 -*-
|
# -*- coding: UTF-8 -*-
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from librouteros.protocol import (
|
from .protocol import (
|
||||||
cast_to_api,
|
cast_to_api,
|
||||||
)
|
)
|
||||||
|
|
|
@ -11,12 +11,12 @@ from .const import (
|
||||||
DEFAULT_ENCODING,
|
DEFAULT_ENCODING,
|
||||||
)
|
)
|
||||||
|
|
||||||
MODULE_PATH = os.path.join(os.path.dirname(__file__), "librouteros", "__init__.py")
|
MODULE_PATH = os.path.join(os.path.dirname(__file__), "librouteros_custom", "__init__.py")
|
||||||
MODULE_NAME = "librouteros"
|
MODULE_NAME = "librouteros_custom"
|
||||||
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
|
spec = importlib.util.spec_from_file_location(MODULE_NAME, MODULE_PATH)
|
||||||
librouteros = importlib.util.module_from_spec(spec)
|
librouteros_custom = importlib.util.module_from_spec(spec)
|
||||||
sys.modules[spec.name] = librouteros
|
sys.modules[spec.name] = librouteros_custom
|
||||||
spec.loader.exec_module(librouteros)
|
spec.loader.exec_module(librouteros_custom)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
@ -69,13 +69,13 @@ class MikrotikAPI:
|
||||||
kwargs["ssl_wrapper"] = self._ssl_wrapper
|
kwargs["ssl_wrapper"] = self._ssl_wrapper
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._connection = librouteros.connect(self._host, self._username, self._password, **kwargs)
|
self._connection = librouteros_custom.connect(self._host, self._username, self._password, **kwargs)
|
||||||
except (
|
except (
|
||||||
librouteros.exceptions.TrapError,
|
librouteros_custom.exceptions.TrapError,
|
||||||
librouteros.exceptions.MultiTrapError,
|
librouteros_custom.exceptions.MultiTrapError,
|
||||||
librouteros.exceptions.ConnectionClosed,
|
librouteros_custom.exceptions.ConnectionClosed,
|
||||||
librouteros.exceptions.ProtocolError,
|
librouteros_custom.exceptions.ProtocolError,
|
||||||
librouteros.exceptions.FatalError,
|
librouteros_custom.exceptions.FatalError,
|
||||||
ssl.SSLError
|
ssl.SSLError
|
||||||
) as api_error:
|
) as api_error:
|
||||||
_LOGGER.error("Mikrotik %s: %s", self._host, api_error)
|
_LOGGER.error("Mikrotik %s: %s", self._host, api_error)
|
||||||
|
@ -121,16 +121,16 @@ class MikrotikAPI:
|
||||||
try:
|
try:
|
||||||
response = self._connection.path(path)
|
response = self._connection.path(path)
|
||||||
tuple(response)
|
tuple(response)
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
except librouteros_custom.exceptions.ConnectionClosed:
|
||||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._connection = None
|
self._connection = None
|
||||||
return None
|
return None
|
||||||
except (
|
except (
|
||||||
librouteros.exceptions.TrapError,
|
librouteros_custom.exceptions.TrapError,
|
||||||
librouteros.exceptions.MultiTrapError,
|
librouteros_custom.exceptions.MultiTrapError,
|
||||||
librouteros.exceptions.ProtocolError,
|
librouteros_custom.exceptions.ProtocolError,
|
||||||
librouteros.exceptions.FatalError
|
librouteros_custom.exceptions.FatalError
|
||||||
) as api_error:
|
) as api_error:
|
||||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||||
return None
|
return None
|
||||||
|
@ -166,16 +166,16 @@ class MikrotikAPI:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response.update(**params)
|
response.update(**params)
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
except librouteros_custom.exceptions.ConnectionClosed:
|
||||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._connection = None
|
self._connection = None
|
||||||
return None
|
return None
|
||||||
except (
|
except (
|
||||||
librouteros.exceptions.TrapError,
|
librouteros_custom.exceptions.TrapError,
|
||||||
librouteros.exceptions.MultiTrapError,
|
librouteros_custom.exceptions.MultiTrapError,
|
||||||
librouteros.exceptions.ProtocolError,
|
librouteros_custom.exceptions.ProtocolError,
|
||||||
librouteros.exceptions.FatalError
|
librouteros_custom.exceptions.FatalError
|
||||||
) as api_error:
|
) as api_error:
|
||||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||||
return None
|
return None
|
||||||
|
@ -210,16 +210,16 @@ class MikrotikAPI:
|
||||||
entry_found = True
|
entry_found = True
|
||||||
try:
|
try:
|
||||||
run = response('run', **{'.id': tmp['.id']})
|
run = response('run', **{'.id': tmp['.id']})
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
except librouteros_custom.exceptions.ConnectionClosed:
|
||||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._connection = None
|
self._connection = None
|
||||||
return None
|
return None
|
||||||
except (
|
except (
|
||||||
librouteros.exceptions.TrapError,
|
librouteros_custom.exceptions.TrapError,
|
||||||
librouteros.exceptions.MultiTrapError,
|
librouteros_custom.exceptions.MultiTrapError,
|
||||||
librouteros.exceptions.ProtocolError,
|
librouteros_custom.exceptions.ProtocolError,
|
||||||
librouteros.exceptions.FatalError
|
librouteros_custom.exceptions.FatalError
|
||||||
) as api_error:
|
) as api_error:
|
||||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||||
return None
|
return None
|
||||||
|
@ -249,16 +249,16 @@ class MikrotikAPI:
|
||||||
args = {'interface': interfaces, 'once': True}
|
args = {'interface': interfaces, 'once': True}
|
||||||
try:
|
try:
|
||||||
traffic = response('monitor-traffic', **args)
|
traffic = response('monitor-traffic', **args)
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
except librouteros_custom.exceptions.ConnectionClosed:
|
||||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||||
self._connected = False
|
self._connected = False
|
||||||
self._connection = None
|
self._connection = None
|
||||||
return None
|
return None
|
||||||
except (
|
except (
|
||||||
librouteros.exceptions.TrapError,
|
librouteros_custom.exceptions.TrapError,
|
||||||
librouteros.exceptions.MultiTrapError,
|
librouteros_custom.exceptions.MultiTrapError,
|
||||||
librouteros.exceptions.ProtocolError,
|
librouteros_custom.exceptions.ProtocolError,
|
||||||
librouteros.exceptions.FatalError
|
librouteros_custom.exceptions.FatalError
|
||||||
) as api_error:
|
) as api_error:
|
||||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue