mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-12 10:24:30 +02:00
added exception ApiEntryNotFound
This commit is contained in:
parent
8f8817a1f7
commit
6467673dce
2 changed files with 18 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
import ssl
|
||||
import logging
|
||||
import librouteros
|
||||
from .exceptions import OldLibrouteros
|
||||
from .exceptions import OldLibrouteros, ApiEntryNotFound
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
@ -138,6 +138,7 @@ class MikrotikAPI:
|
|||
# ---------------------------
|
||||
def update(self, path, param, value, mod_param, mod_value):
|
||||
"""Modify a parameter"""
|
||||
entry_found = False
|
||||
if not self._connected or not self._connection:
|
||||
if not self.connect():
|
||||
return None
|
||||
|
@ -153,6 +154,7 @@ class MikrotikAPI:
|
|||
if tmp[param] != value:
|
||||
continue
|
||||
|
||||
entry_found = True
|
||||
params = {
|
||||
'.id': tmp['.id'],
|
||||
mod_param: mod_value
|
||||
|
@ -174,6 +176,10 @@ class MikrotikAPI:
|
|||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
|
||||
if not entry_found:
|
||||
error = "Parameter \"{}\" with value \"{}\" not found".format(param, value)
|
||||
raise ApiEntryNotFound(error)
|
||||
|
||||
return True
|
||||
|
||||
# ---------------------------
|
||||
|
@ -181,6 +187,7 @@ class MikrotikAPI:
|
|||
# ---------------------------
|
||||
def run_script(self, name):
|
||||
"""Run script"""
|
||||
entry_found = False
|
||||
if not self._connected or not self._connection:
|
||||
if not self.connect():
|
||||
return None
|
||||
|
@ -196,6 +203,7 @@ class MikrotikAPI:
|
|||
if tmp['name'] != name:
|
||||
continue
|
||||
|
||||
entry_found = True
|
||||
try:
|
||||
run = response('run', **{'.id': tmp['.id']})
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
|
@ -214,4 +222,8 @@ class MikrotikAPI:
|
|||
|
||||
tuple(run)
|
||||
|
||||
if not entry_found:
|
||||
error = "Script \"{}\" not found".format(name)
|
||||
raise ApiEntryNotFound(error)
|
||||
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue