mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-13 19:04:30 +02:00
Use comment as name when available, make sensor more granular #20
This commit is contained in:
parent
68e0b4c288
commit
49631e2826
2 changed files with 38 additions and 9 deletions
|
@ -734,11 +734,14 @@ class MikrotikControllerData:
|
|||
key=".id",
|
||||
vals=[
|
||||
{"name": ".id"},
|
||||
{"name": "chain", "default": "unknown"},
|
||||
{"name": "action", "default": "unknown"},
|
||||
{"name": "protocol", "default": "any"},
|
||||
{"name": "dst-port", "default": "any"},
|
||||
{"name": "in-interface", "default": "any"},
|
||||
{"name": "out-interface", "default": "any"},
|
||||
{"name": "to-addresses"},
|
||||
{"name": "to-ports"},
|
||||
{"name": "to-ports", "default": "any"},
|
||||
{"name": "comment"},
|
||||
{
|
||||
"name": "enabled",
|
||||
|
@ -748,13 +751,32 @@ class MikrotikControllerData:
|
|||
},
|
||||
],
|
||||
val_proc=[
|
||||
[
|
||||
{"name": "uniq-id"},
|
||||
{"action": "combine"},
|
||||
{"key": "chain"},
|
||||
{"text": ","},
|
||||
{"key": "action"},
|
||||
{"text": ","},
|
||||
{"key": "protocol"},
|
||||
{"text": ","},
|
||||
{"key": "in-interface"},
|
||||
{"text": ":"},
|
||||
{"key": "dst-port"},
|
||||
{"text": "-"},
|
||||
{"key": "out-interface"},
|
||||
{"text": ":"},
|
||||
{"key": "to-addresses"},
|
||||
{"text": ":"},
|
||||
{"key": "to-ports"},
|
||||
],
|
||||
[
|
||||
{"name": "name"},
|
||||
{"action": "combine"},
|
||||
{"key": "protocol"},
|
||||
{"text": ":"},
|
||||
{"key": "dst-port"},
|
||||
]
|
||||
],
|
||||
],
|
||||
only=[{"key": "action", "value": "dst-nat"}],
|
||||
)
|
||||
|
|
|
@ -132,11 +132,11 @@ def update_items(inst, mikrotik_controller, async_add_entities, switches):
|
|||
# Data point name
|
||||
["interface", "nat", "mangle", "ppp_secret", "script", "queue"],
|
||||
# Data point unique id
|
||||
["name", "name", "name", "name", "name", "name"],
|
||||
["name", "uniq-id", "name", "name", "name", "name"],
|
||||
# Entry Name
|
||||
["name", "name", "comment", "name", "name", "name"],
|
||||
# Entry Unique id
|
||||
["port-mac-address", "name", "name", "name", "name", "name"],
|
||||
["port-mac-address", "uniq-id", "name", "name", "name", "name"],
|
||||
# Attr
|
||||
[
|
||||
DEVICE_ATTRIBUTES_IFACE,
|
||||
|
@ -338,8 +338,16 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the NAT switch."""
|
||||
if self._data["comment"]:
|
||||
return f"{self._inst} NAT {self._data['comment']}"
|
||||
|
||||
return f"{self._inst} NAT {self._data['name']}"
|
||||
|
||||
@property
|
||||
def unique_id(self) -> str:
|
||||
"""Return a unique identifier for this mangle switch."""
|
||||
return f"{self._inst.lower()}-enable_nat-{self._data['uniq-id']}"
|
||||
|
||||
@property
|
||||
def icon(self):
|
||||
"""Return the icon."""
|
||||
|
@ -376,8 +384,8 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
|||
value = None
|
||||
for uid in self._ctrl.data["nat"]:
|
||||
if (
|
||||
self._ctrl.data["nat"][uid]["name"]
|
||||
== f"{self._data['protocol']}:{self._data['dst-port']}"
|
||||
self._ctrl.data["nat"][uid]["uniq-id"]
|
||||
== f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['in-interface']}:{self._data['dst-port']}-{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
||||
):
|
||||
value = self._ctrl.data["nat"][uid][".id"]
|
||||
|
||||
|
@ -393,8 +401,8 @@ class MikrotikControllerNATSwitch(MikrotikControllerSwitch):
|
|||
value = None
|
||||
for uid in self._ctrl.data["nat"]:
|
||||
if (
|
||||
self._ctrl.data["nat"][uid]["name"]
|
||||
== f"{self._data['protocol']}:{self._data['dst-port']}"
|
||||
self._ctrl.data["nat"][uid]["uniq-id"]
|
||||
== f"{self._data['chain']},{self._data['action']},{self._data['protocol']},{self._data['in-interface']}:{self._data['dst-port']}-{self._data['out-interface']}:{self._data['to-addresses']}:{self._data['to-ports']}"
|
||||
):
|
||||
value = self._ctrl.data["nat"][uid][".id"]
|
||||
|
||||
|
@ -504,7 +512,6 @@ class MikrotikControllerPPPSecretSwitch(MikrotikControllerSwitch):
|
|||
@property
|
||||
def name(self) -> str:
|
||||
"""Return the name of the PPP Secret switch."""
|
||||
|
||||
return f"{self._inst} PPP Secret {self._data['name']}"
|
||||
|
||||
@property
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue