mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-06-28 19:50:06 +02:00
API, option for path command to execute commands in path and pass arguments
This commit is contained in:
parent
a76417c240
commit
8efaa72492
1 changed files with 12 additions and 2 deletions
|
@ -177,9 +177,11 @@ class MikrotikAPI:
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
# path
|
# path
|
||||||
# ---------------------------
|
# ---------------------------
|
||||||
def path(self, path, return_list=True) -> Optional(list):
|
def path(self, path, command=None, args=None, return_list=True) -> Optional(list):
|
||||||
"""Retrieve data from Mikrotik API."""
|
"""Retrieve data from Mikrotik API."""
|
||||||
"""Returns generator object, unless return_list passed as True"""
|
"""Returns generator object, unless return_list passed as True"""
|
||||||
|
if args is None:
|
||||||
|
args = {}
|
||||||
|
|
||||||
if not self.connection_check():
|
if not self.connection_check():
|
||||||
return None
|
return None
|
||||||
|
@ -193,13 +195,21 @@ class MikrotikAPI:
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if return_list:
|
if response and return_list and not command:
|
||||||
try:
|
try:
|
||||||
response = list(response)
|
response = list(response)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.disconnect("building list for path", e)
|
self.disconnect("building list for path", e)
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return None
|
return None
|
||||||
|
elif response and command:
|
||||||
|
_LOGGER.debug("API query: %s, %s, %s", path, command, args)
|
||||||
|
try:
|
||||||
|
response = list(response(command, **args))
|
||||||
|
except Exception as e:
|
||||||
|
self.disconnect("path", e)
|
||||||
|
self.lock.release()
|
||||||
|
return None
|
||||||
|
|
||||||
self.lock.release()
|
self.lock.release()
|
||||||
return response or None
|
return response or None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue