From ec1788ad3a88b72b63929f4dbddbb43f6ca0f218 Mon Sep 17 00:00:00 2001 From: tomaae <23486452+tomaae@users.noreply.github.com> Date: Fri, 25 Dec 2020 22:57:12 +0100 Subject: [PATCH] Changed mangle name to be more user friendly #75 --- .../mikrotik_router/mikrotik_controller.py | 19 ++++++++++++++----- custom_components/mikrotik_router/switch.py | 12 ++++++------ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/custom_components/mikrotik_router/mikrotik_controller.py b/custom_components/mikrotik_router/mikrotik_controller.py index 74bde40..d0f818f 100644 --- a/custom_components/mikrotik_router/mikrotik_controller.py +++ b/custom_components/mikrotik_router/mikrotik_controller.py @@ -850,7 +850,7 @@ class MikrotikControllerData: ], val_proc=[ [ - {"name": "name"}, + {"name": "uniq-id"}, {"action": "combine"}, {"key": "chain"}, {"text": ","}, @@ -865,7 +865,16 @@ class MikrotikControllerData: {"key": "dst-address"}, {"text": ":"}, {"key": "dst-port"}, - ] + ], + [ + {"name": "name"}, + {"action": "combine"}, + {"key": "action"}, + {"text": ","}, + {"key": "protocol"}, + {"text": ":"}, + {"key": "dst-port"}, + ], ], skip=[ {"name": "dynamic", "value": True}, @@ -877,7 +886,7 @@ class MikrotikControllerData: mangle_uniq = {} mangle_del = {} for uid in self.data["mangle"]: - tmp_name = self.data["mangle"][uid]["name"] + tmp_name = self.data["mangle"][uid]["uniq-id"] if tmp_name not in mangle_uniq: mangle_uniq[tmp_name] = uid else: @@ -885,8 +894,8 @@ class MikrotikControllerData: mangle_del[mangle_uniq[tmp_name]] = 1 for uid in mangle_del: - if self.data["mangle"][uid]["name"] not in self.mangle_removed: - self.mangle_removed[self.data["mangle"][uid]["name"]] = 1 + if self.data["mangle"][uid]["uniq-id"] not in self.mangle_removed: + self.mangle_removed[self.data["mangle"][uid]["uniq-id"]] = 1 _LOGGER.error( "Mikrotik %s duplicate Mangle rule %s, entity will be unavailable.", self.host, diff --git a/custom_components/mikrotik_router/switch.py b/custom_components/mikrotik_router/switch.py index fc114b2..8cb769f 100644 --- a/custom_components/mikrotik_router/switch.py +++ b/custom_components/mikrotik_router/switch.py @@ -145,11 +145,11 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches): # Data point name ["interface", "nat", "mangle", "ppp_secret", "script", "queue", "kid-control"], # Data point unique id - ["name", "uniq-id", "name", "name", "name", "name", "name"], + ["name", "uniq-id", "uniq-id", "name", "name", "name", "name"], # Entry Name - ["name", "name", "comment", "name", "name", "name", "name"], + ["name", "name", "name", "name", "name", "name", "name"], # Entry Unique id - ["port-mac-address", "uniq-id", "name", "name", "name", "name", "name"], + ["port-mac-address", "uniq-id", "uniq-id", "name", "name", "name", "name"], # Attr [ DEVICE_ATTRIBUTES_IFACE, @@ -448,7 +448,7 @@ class MikrotikControllerMangleSwitch(MikrotikControllerSwitch): @property def unique_id(self) -> str: """Return a unique id for this entity.""" - return f"{self._inst.lower()}-enable_mangle-{self._data['name']}" + return f"{self._inst.lower()}-enable_mangle-{self._data['uniq-id']}" @property def icon(self) -> str: @@ -486,7 +486,7 @@ class MikrotikControllerMangleSwitch(MikrotikControllerSwitch): value = None for uid in self._ctrl.data["mangle"]: if ( - self._ctrl.data["mangle"][uid]["name"] + self._ctrl.data["mangle"][uid]["uniq-id"] == f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['src-address']}:{self._data['src-port']}-{self._data['dst-address']}:{self._data['dst-port']}" ): value = self._ctrl.data["mangle"][uid][".id"] @@ -503,7 +503,7 @@ class MikrotikControllerMangleSwitch(MikrotikControllerSwitch): value = None for uid in self._ctrl.data["mangle"]: if ( - self._ctrl.data["mangle"][uid]["name"] + self._ctrl.data["mangle"][uid]["uniq-id"] == f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['src-address']}:{self._data['src-port']}-{self._data['dst-address']}:{self._data['dst-port']}" ): value = self._ctrl.data["mangle"][uid][".id"]