API, option for path command to execute commands in path and pass arguments

This commit is contained in:
Tomaae 2022-06-28 20:12:41 +02:00
parent a76417c240
commit 8efaa72492
No known key found for this signature in database
GPG key ID: 8360BBD8A381D1C0

View file

@ -177,9 +177,11 @@ class MikrotikAPI:
# ---------------------------
# 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."""
"""Returns generator object, unless return_list passed as True"""
if args is None:
args = {}
if not self.connection_check():
return None
@ -193,13 +195,21 @@ class MikrotikAPI:
self.lock.release()
return None
if return_list:
if response and return_list and not command:
try:
response = list(response)
except Exception as e:
self.disconnect("building list for path", e)
self.lock.release()
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()
return response or None