diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 8e9e28b..8cb58e1 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -45,6 +45,7 @@ def __init__( """Initialize MikrotikController.""" self.name = name self.hass = hass + self.host = host self.config_entry = config_entry self.traffic_type = traffic_type @@ -64,6 +65,8 @@ def __init__( self.api = MikrotikAPI(host, username, password, port, use_ssl) + self.nat_removed = {} + async_track_time_interval( self.hass, self.force_update, self.option_scan_interval ) @@ -462,6 +465,24 @@ def get_nat(self): only=[{"key": "action", "value": "dst-nat"}], ) + nat_uniq = {} + nat_del = {} + for uid in self.data["nat"]: + tmp_name = self.data["nat"][uid]["name"] + if tmp_name not in nat_uniq: + nat_uniq[tmp_name] = uid + else: + nat_del[uid] = 1 + nat_del[nat_uniq[tmp_name]] = 1 + + for uid in nat_del: + if self.data["nat"][uid]["name"] not in self.nat_removed: + self.nat_removed[self.data["nat"][uid]["name"]] = 1 + _LOGGER.error("Mikrotik %s duplicate NAT rule %s, entity will be unavailable.", + self.host, self.data["nat"][uid]["name"]) + + del self.data["nat"][uid] + # --------------------------- # get_system_routerboard # ---------------------------