mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-26 10:48:41 +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,9 +271,19 @@ 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
|
||||||
|
|
||||||
|
if not entry_found:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Mikrotik %s Update parameter %s with value %s not found",
|
||||||
|
self._host,
|
||||||
|
param,
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
|
params = {".id": entry_found, mod_param: mod_value}
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
try:
|
try:
|
||||||
response.update(**params)
|
response.update(**params)
|
||||||
|
@ -302,22 +312,14 @@ class MikrotikAPI:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
if not entry_found:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Mikrotik %s Update parameter %s with value %s not found",
|
|
||||||
self._host,
|
|
||||||
param,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
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,9 +335,20 @@ class MikrotikAPI:
|
||||||
if tmp[param] != value:
|
if tmp[param] != value:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_found = True
|
entry_found = tmp[".id"]
|
||||||
|
break
|
||||||
|
|
||||||
|
if not entry_found:
|
||||||
|
_LOGGER.error(
|
||||||
|
"Mikrotik %s Execute %s parameter %s with value %s not found",
|
||||||
|
self._host,
|
||||||
|
command,
|
||||||
|
param,
|
||||||
|
value,
|
||||||
|
)
|
||||||
|
return True
|
||||||
|
|
||||||
params = {".id": tmp[".id"]}
|
params = {".id": tmp[".id"]}
|
||||||
print(params)
|
|
||||||
self.lock.acquire()
|
self.lock.acquire()
|
||||||
try:
|
try:
|
||||||
tuple(response(command, **params))
|
tuple(response(command, **params))
|
||||||
|
@ -364,15 +377,6 @@ class MikrotikAPI:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
if not entry_found:
|
|
||||||
_LOGGER.error(
|
|
||||||
"Mikrotik %s Execute %s parameter %s with value %s not found",
|
|
||||||
self._host,
|
|
||||||
command,
|
|
||||||
param,
|
|
||||||
value,
|
|
||||||
)
|
|
||||||
|
|
||||||
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,9 +400,14 @@ class MikrotikAPI:
|
||||||
if tmp["name"] != name:
|
if tmp["name"] != name:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
entry_found = True
|
entry_found = tmp[".id"]
|
||||||
|
|
||||||
|
if not entry_found:
|
||||||
|
_LOGGER.error("Mikrotik %s Script %s not found", self._host, name)
|
||||||
|
return True
|
||||||
|
|
||||||
try:
|
try:
|
||||||
run = response("run", **{".id": tmp[".id"]})
|
run = response("run", **{".id": entry_found})
|
||||||
tuple(run)
|
tuple(run)
|
||||||
except librouteros.exceptions.ConnectionClosed:
|
except librouteros.exceptions.ConnectionClosed:
|
||||||
self.disconnect()
|
self.disconnect()
|
||||||
|
@ -425,9 +434,6 @@ class MikrotikAPI:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
if not entry_found:
|
|
||||||
_LOGGER.error("Mikrotik %s Script %s not found", self._host, name)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue