From bd56487f4205d5313347de4b0386cd71d0d190ad Mon Sep 17 00:00:00 2001 From: Tomaae <23486452+tomaae@users.noreply.github.com> Date: Fri, 27 May 2022 10:58:51 +0200 Subject: [PATCH] force check for firmware update, fixes #208 --- .../mikrotik_router/mikrotik_controller.py | 1 + .../mikrotik_router/mikrotikapi.py | 35 ++++++++++--------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 19d5aa2..ee6e0df 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -1455,6 +1455,7 @@ class MikrotikControllerData: # --------------------------- def get_firmware_update(self): """Check for firmware update on Mikrotik""" + self.execute("/system/package/update", "check-for-updates", None, None) self.data["fw-update"] = parse_api( data=self.data["fw-update"], source=self.api.path("/system/package/update"), diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index 71947b5..7e4da3e 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -319,6 +319,7 @@ class MikrotikAPI: def execute(self, path, command, param, value) -> bool: """Execute a command""" entry_found = None + params = {} if not self.connection_check(): return False @@ -327,26 +328,28 @@ class MikrotikAPI: if response is None: return False - for tmp in response: - if param not in tmp: - continue + if param: + for tmp in response: + if param not in tmp: + continue - if tmp[param] != value: - continue + if tmp[param] != value: + continue - entry_found = tmp[".id"] + entry_found = tmp[".id"] - if not entry_found: - _LOGGER.error( - "Mikrotik %s Execute %s parameter %s with value %s not found", - self._host, - command, - param, - value, - ) - return True + 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": entry_found} - params = {".id": entry_found} self.lock.acquire() try: tuple(response(command, **params))