mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-22 00:49:02 +02:00
updated exceptions in api for only needed parts
This commit is contained in:
parent
d991d14a35
commit
fc9939aeab
1 changed files with 50 additions and 49 deletions
|
@ -127,37 +127,37 @@ class MikrotikAPI:
|
|||
if not self.connect():
|
||||
return None
|
||||
|
||||
try:
|
||||
response = self.path(path)
|
||||
if response is None:
|
||||
return False
|
||||
response = self.path(path)
|
||||
if response is None:
|
||||
return False
|
||||
|
||||
for tmp in response:
|
||||
if param not in tmp:
|
||||
continue
|
||||
for tmp in response:
|
||||
if param not in tmp:
|
||||
continue
|
||||
|
||||
if tmp[param] != value:
|
||||
continue
|
||||
if tmp[param] != value:
|
||||
continue
|
||||
|
||||
params = {
|
||||
'.id': tmp['.id'],
|
||||
mod_param: mod_value
|
||||
}
|
||||
params = {
|
||||
'.id': tmp['.id'],
|
||||
mod_param: mod_value
|
||||
}
|
||||
|
||||
try:
|
||||
response.update(**params)
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self._connected = False
|
||||
self._connection = None
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self._connected = False
|
||||
self._connection = None
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
|
||||
return True
|
||||
|
||||
|
@ -170,32 +170,33 @@ class MikrotikAPI:
|
|||
if not self.connect():
|
||||
return None
|
||||
|
||||
try:
|
||||
response = self.path('/system/script')
|
||||
if response is None:
|
||||
return False
|
||||
response = self.path('/system/script')
|
||||
if response is None:
|
||||
return False
|
||||
|
||||
for tmp in response:
|
||||
if 'name' not in tmp:
|
||||
continue
|
||||
for tmp in response:
|
||||
if 'name' not in tmp:
|
||||
continue
|
||||
|
||||
if tmp['name'] != name:
|
||||
continue
|
||||
if tmp['name'] != name:
|
||||
continue
|
||||
|
||||
try:
|
||||
run = response('run', **{'.id': tmp['.id']})
|
||||
tuple(run)
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self._connected = False
|
||||
self._connection = None
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
except librouteros.exceptions.ConnectionClosed:
|
||||
_LOGGER.error("Mikrotik %s connection closed", self._host)
|
||||
self._connected = False
|
||||
self._connection = None
|
||||
return None
|
||||
except (
|
||||
librouteros.exceptions.TrapError,
|
||||
librouteros.exceptions.MultiTrapError,
|
||||
librouteros.exceptions.ProtocolError,
|
||||
librouteros.exceptions.FatalError
|
||||
) as api_error:
|
||||
_LOGGER.error("Mikrotik %s connection error %s", self._host, api_error)
|
||||
return None
|
||||
|
||||
tuple(run)
|
||||
|
||||
return True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue