mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-23 17:28:51 +02:00
removed trailing whitespace from empty lines
This commit is contained in:
parent
7d9470133e
commit
b851085f48
8 changed files with 212 additions and 212 deletions
|
@ -11,7 +11,7 @@ _LOGGER = logging.getLogger(__name__)
|
|||
# ---------------------------
|
||||
class MikrotikAPI:
|
||||
"""Handle all communication with the Mikrotik API."""
|
||||
|
||||
|
||||
def __init__(self, host, username, password, port=0, use_ssl=True, login_method="plain", encoding="utf-8"):
|
||||
"""Initialize the Mikrotik Client."""
|
||||
self._host = host
|
||||
|
@ -22,15 +22,15 @@ class MikrotikAPI:
|
|||
self._login_method = login_method
|
||||
self._encoding = encoding
|
||||
self._ssl_wrapper = None
|
||||
|
||||
|
||||
self._connection = None
|
||||
self._connected = False
|
||||
self.error = ""
|
||||
|
||||
|
||||
# Default ports
|
||||
if not self._port:
|
||||
self._port = 8729 if self._use_ssl else 8728
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# connect
|
||||
# ---------------------------
|
||||
|
@ -38,13 +38,13 @@ class MikrotikAPI:
|
|||
"""Connect to Mikrotik device."""
|
||||
self.error = ""
|
||||
self._connected = False
|
||||
|
||||
|
||||
kwargs = {
|
||||
"encoding": self._encoding,
|
||||
"login_methods": self._login_method,
|
||||
"port": self._port,
|
||||
}
|
||||
|
||||
|
||||
if self._use_ssl:
|
||||
if self._ssl_wrapper is None:
|
||||
ssl_context = ssl.create_default_context()
|
||||
|
@ -52,7 +52,7 @@ class MikrotikAPI:
|
|||
ssl_context.verify_mode = ssl.CERT_NONE
|
||||
self._ssl_wrapper = ssl_context.wrap_socket
|
||||
kwargs["ssl_wrapper"] = self._ssl_wrapper
|
||||
|
||||
|
||||
try:
|
||||
self._connection = librouteros.connect(self._host, self._username, self._password, **kwargs)
|
||||
except (
|
||||
|
@ -69,9 +69,9 @@ class MikrotikAPI:
|
|||
else:
|
||||
_LOGGER.info("Mikrotik Connected to %s", self._host)
|
||||
self._connected = True
|
||||
|
||||
|
||||
return self._connected
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# error_to_strings
|
||||
# ---------------------------
|
||||
|
@ -80,16 +80,16 @@ class MikrotikAPI:
|
|||
self.error = "cannot_connect"
|
||||
if error == "invalid user name or password (6)":
|
||||
self.error = "wrong_login"
|
||||
|
||||
|
||||
return
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# connected
|
||||
# ---------------------------
|
||||
def connected(self):
|
||||
"""Return connected boolean."""
|
||||
return self._connected
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# path
|
||||
# ---------------------------
|
||||
|
@ -98,7 +98,7 @@ class MikrotikAPI:
|
|||
if not self._connected or not self._connection:
|
||||
if not self.connect():
|
||||
return None
|
||||
|
||||
|
||||
try:
|
||||
response = self._connection.path(path)
|
||||
tuple(response)
|
||||
|
@ -115,9 +115,9 @@ class MikrotikAPI:
|
|||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
|
||||
|
||||
return response if response else None
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# update
|
||||
# ---------------------------
|
||||
|
@ -126,23 +126,23 @@ class MikrotikAPI:
|
|||
response = self.path(path)
|
||||
if response is None:
|
||||
return False
|
||||
|
||||
|
||||
for tmp in response:
|
||||
if param not in tmp:
|
||||
continue
|
||||
|
||||
|
||||
if tmp[param] != value:
|
||||
continue
|
||||
|
||||
|
||||
params = {
|
||||
'.id': tmp['.id'],
|
||||
mod_param: mod_value
|
||||
}
|
||||
|
||||
|
||||
response.update(**params)
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
# ---------------------------
|
||||
# run_script
|
||||
# ---------------------------
|
||||
|
@ -151,15 +151,15 @@ class MikrotikAPI:
|
|||
response = self.path('/system/script')
|
||||
if response is None:
|
||||
return False
|
||||
|
||||
|
||||
for tmp in response:
|
||||
if 'name' not in tmp:
|
||||
continue
|
||||
|
||||
|
||||
if tmp['name'] != name:
|
||||
continue
|
||||
|
||||
|
||||
run = response('run', **{'.id': tmp['.id']})
|
||||
tuple(run)
|
||||
|
||||
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue