diff --git a/custom_components/mikrotik_router/exceptions.py b/custom_components/mikrotik_router/exceptions.py new file mode 100644 index 0000000..03cfecb --- /dev/null +++ b/custom_components/mikrotik_router/exceptions.py @@ -0,0 +1,4 @@ +"""Exceptions for Mikrotik Router.""" + +class OldLibrouteros(Exception): + """Old librouteros version.""" diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index 53f7037..00bdf7f 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -3,6 +3,7 @@ import ssl import logging import librouteros +from .exceptions import OldLibrouteros _LOGGER = logging.getLogger(__name__) @@ -27,10 +28,24 @@ class MikrotikAPI: self._connected = False self.error = "" + self.check_library() + # Default ports if not self._port: self._port = 8729 if self._use_ssl else 8728 + # --------------------------- + # check_library + # --------------------------- + def check_library(self): + if not hasattr(librouteros.exceptions, 'ConnectionClosed'): + error = "Old librouteros installed, check for possible conflicts with other integrations." + raise OldLibrouteros(error) + + if not hasattr(librouteros.exceptions, 'ProtocolError'): + error = "Old librouteros installed, check for possible conflicts with other integrations." + raise OldLibrouteros(error) + # --------------------------- # connect # ---------------------------