mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-26 18:58:54 +02:00
Capture permission denied when using switches #80
This commit is contained in:
parent
42ad216802
commit
aebb834420
1 changed files with 98 additions and 92 deletions
|
@ -255,7 +255,7 @@ class MikrotikAPI:
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def update(self, path, param, value, mod_param, mod_value) -> bool:
|
def update(self, path, param, value, mod_param, mod_value) -> bool:
|
||||||
"""Modify a parameter"""
|
"""Modify a parameter"""
|
||||||
entry_found = False
|
entry_found = None
|
||||||
|
|
||||||
if not self.connection_check():
|
if not self.connection_check():
|
||||||
return False
|
return False
|
||||||
|
@ -271,37 +271,9 @@ class MikrotikAPI:
|
||||||
if tmp[param] != value:
|
if tmp[param] != value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_found = True
|
entry_found = tmp[".id"]
|
||||||
params = {".id": tmp[".id"], mod_param: mod_value}
|
break
|
||||||
|
|
||||||
self.lock.acquire()
|
|
||||||
try:
|
|
||||||
response.update(**params)
|
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
|
||||||
self.disconnect()
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except (
|
|
||||||
librouteros.exceptions.TrapError,
|
|
||||||
librouteros.exceptions.MultiTrapError,
|
|
||||||
librouteros.exceptions.ProtocolError,
|
|
||||||
librouteros.exceptions.FatalError,
|
|
||||||
socket_timeout,
|
|
||||||
socket_error,
|
|
||||||
ssl.SSLError,
|
|
||||||
BrokenPipeError,
|
|
||||||
OSError,
|
|
||||||
ValueError,
|
|
||||||
) as api_error:
|
|
||||||
self.disconnect("update", api_error)
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
self.disconnect("update")
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.lock.release()
|
|
||||||
if not entry_found:
|
if not entry_found:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Mikrotik %s Update parameter %s with value %s not found",
|
"Mikrotik %s Update parameter %s with value %s not found",
|
||||||
|
@ -309,15 +281,45 @@ class MikrotikAPI:
|
||||||
param,
|
param,
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
params = {".id": entry_found, mod_param: mod_value}
|
||||||
|
self.lock.acquire()
|
||||||
|
try:
|
||||||
|
response.update(**params)
|
||||||
|
except librouteros.exceptions.ConnectionClosed:
|
||||||
|
self.disconnect()
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except (
|
||||||
|
librouteros.exceptions.TrapError,
|
||||||
|
librouteros.exceptions.MultiTrapError,
|
||||||
|
librouteros.exceptions.ProtocolError,
|
||||||
|
librouteros.exceptions.FatalError,
|
||||||
|
socket_timeout,
|
||||||
|
socket_error,
|
||||||
|
ssl.SSLError,
|
||||||
|
BrokenPipeError,
|
||||||
|
OSError,
|
||||||
|
ValueError,
|
||||||
|
) as api_error:
|
||||||
|
self.disconnect("update", api_error)
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
self.disconnect("update")
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.lock.release()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# execute
|
# execute
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def execute(self, path, command, param, value) -> bool:
|
def execute(self, path, command, param, value) -> bool:
|
||||||
"""Modify a parameter"""
|
"""Execute a command"""
|
||||||
entry_found = False
|
entry_found = None
|
||||||
|
|
||||||
if not self.connection_check():
|
if not self.connection_check():
|
||||||
return False
|
return False
|
||||||
|
@ -333,37 +335,9 @@ class MikrotikAPI:
|
||||||
if tmp[param] != value:
|
if tmp[param] != value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_found = True
|
entry_found = tmp[".id"]
|
||||||
params = {".id": tmp[".id"]}
|
break
|
||||||
print(params)
|
|
||||||
self.lock.acquire()
|
|
||||||
try:
|
|
||||||
tuple(response(command, **params))
|
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
|
||||||
self.disconnect()
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except (
|
|
||||||
librouteros.exceptions.TrapError,
|
|
||||||
librouteros.exceptions.MultiTrapError,
|
|
||||||
librouteros.exceptions.ProtocolError,
|
|
||||||
librouteros.exceptions.FatalError,
|
|
||||||
socket_timeout,
|
|
||||||
socket_error,
|
|
||||||
ssl.SSLError,
|
|
||||||
BrokenPipeError,
|
|
||||||
OSError,
|
|
||||||
ValueError,
|
|
||||||
) as api_error:
|
|
||||||
self.disconnect("execute", api_error)
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
self.disconnect("execute")
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.lock.release()
|
|
||||||
if not entry_found:
|
if not entry_found:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Mikrotik %s Execute %s parameter %s with value %s not found",
|
"Mikrotik %s Execute %s parameter %s with value %s not found",
|
||||||
|
@ -372,7 +346,37 @@ class MikrotikAPI:
|
||||||
param,
|
param,
|
||||||
value,
|
value,
|
||||||
)
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
params = {".id": tmp[".id"]}
|
||||||
|
self.lock.acquire()
|
||||||
|
try:
|
||||||
|
tuple(response(command, **params))
|
||||||
|
except librouteros.exceptions.ConnectionClosed:
|
||||||
|
self.disconnect()
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except (
|
||||||
|
librouteros.exceptions.TrapError,
|
||||||
|
librouteros.exceptions.MultiTrapError,
|
||||||
|
librouteros.exceptions.ProtocolError,
|
||||||
|
librouteros.exceptions.FatalError,
|
||||||
|
socket_timeout,
|
||||||
|
socket_error,
|
||||||
|
ssl.SSLError,
|
||||||
|
BrokenPipeError,
|
||||||
|
OSError,
|
||||||
|
ValueError,
|
||||||
|
) as api_error:
|
||||||
|
self.disconnect("execute", api_error)
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
self.disconnect("execute")
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.lock.release()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
@ -380,7 +384,7 @@ class MikrotikAPI:
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def run_script(self, name) -> bool:
|
def run_script(self, name) -> bool:
|
||||||
"""Run script"""
|
"""Run script"""
|
||||||
entry_found = False
|
entry_found = None
|
||||||
if not self.connection_check():
|
if not self.connection_check():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -396,38 +400,40 @@ class MikrotikAPI:
|
||||||
if tmp["name"] != name:
|
if tmp["name"] != name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_found = True
|
entry_found = tmp[".id"]
|
||||||
try:
|
|
||||||
run = response("run", **{".id": tmp[".id"]})
|
|
||||||
tuple(run)
|
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
|
||||||
self.disconnect()
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except (
|
|
||||||
librouteros.exceptions.TrapError,
|
|
||||||
librouteros.exceptions.MultiTrapError,
|
|
||||||
librouteros.exceptions.ProtocolError,
|
|
||||||
librouteros.exceptions.FatalError,
|
|
||||||
socket_timeout,
|
|
||||||
socket_error,
|
|
||||||
ssl.SSLError,
|
|
||||||
BrokenPipeError,
|
|
||||||
OSError,
|
|
||||||
ValueError,
|
|
||||||
) as api_error:
|
|
||||||
self.disconnect("run_script", api_error)
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
except:
|
|
||||||
self.disconnect("run_script")
|
|
||||||
self.lock.release()
|
|
||||||
return False
|
|
||||||
|
|
||||||
self.lock.release()
|
|
||||||
if not entry_found:
|
if not entry_found:
|
||||||
_LOGGER.error("Mikrotik %s Script %s not found", self._host, name)
|
_LOGGER.error("Mikrotik %s Script %s not found", self._host, name)
|
||||||
|
return True
|
||||||
|
|
||||||
|
try:
|
||||||
|
run = response("run", **{".id": entry_found})
|
||||||
|
tuple(run)
|
||||||
|
except librouteros.exceptions.ConnectionClosed:
|
||||||
|
self.disconnect()
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except (
|
||||||
|
librouteros.exceptions.TrapError,
|
||||||
|
librouteros.exceptions.MultiTrapError,
|
||||||
|
librouteros.exceptions.ProtocolError,
|
||||||
|
librouteros.exceptions.FatalError,
|
||||||
|
socket_timeout,
|
||||||
|
socket_error,
|
||||||
|
ssl.SSLError,
|
||||||
|
BrokenPipeError,
|
||||||
|
OSError,
|
||||||
|
ValueError,
|
||||||
|
) as api_error:
|
||||||
|
self.disconnect("run_script", api_error)
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
except:
|
||||||
|
self.disconnect("run_script")
|
||||||
|
self.lock.release()
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.lock.release()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue