mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-10 01:14:33 +02:00
Changed mangle name to be more user friendly #75
This commit is contained in:
parent
88c79bcada
commit
ec1788ad3a
2 changed files with 20 additions and 11 deletions
|
@ -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,
|
||||
|
|
|
@ -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"]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue