diff --git a/custom_components/mikrotik_router/coordinator.py b/custom_components/mikrotik_router/coordinator.py index 5ceee38..377a49a 100644 --- a/custom_components/mikrotik_router/coordinator.py +++ b/custom_components/mikrotik_router/coordinator.py @@ -1428,8 +1428,9 @@ class MikrotikCoordinator(DataUpdateCoordinator[None]): {"name": "value", "default": "unknown"}, ], ) - for uid, vals in self.ds["health7"].items(): - self.ds["health"][uid] = vals["value"] + if self.ds["health7"]: + for uid, vals in self.ds["health7"].items(): + self.ds["health"][uid] = vals["value"] # --------------------------- # get_system_resource diff --git a/custom_components/mikrotik_router/mikrotikapi.py b/custom_components/mikrotik_router/mikrotikapi.py index ed8f1f5..02de169 100644 --- a/custom_components/mikrotik_router/mikrotikapi.py +++ b/custom_components/mikrotik_router/mikrotikapi.py @@ -52,6 +52,7 @@ class MikrotikAPI: self.error = None self.connection_error_reported = False self.client_traffic_last_run = None + self.disable_health = False # Default ports if not self._port: @@ -186,6 +187,9 @@ class MikrotikAPI: def query(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 path == "/system/health" and self.disable_health: + return None + if args is None: args = {} @@ -205,9 +209,15 @@ class MikrotikAPI: try: response = list(response) except Exception as e: + if path == "/system/health" and "no such command prefix" in str(e): + self.disable_health = True + self.lock.release() + return None + self.disconnect(f"building list for path {path}", e) self.lock.release() return None + elif response and command: _LOGGER.debug("API query: %s, %s, %s", path, command, args) try: