From 8efaa72492d79ff19d966fe08d6e02020113bcae Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Tue, 28 Jun 2022 20:12:41 +0200 Subject: [PATCH] API, option for path command to execute commands in path and pass arguments --- custom_components/mikrotik_router/mikrotikapi.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index 67ba89b..6dd2c03 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -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